From a1e1f73bcb2a4541fe0d5bb72d13a2fc0f243f6f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 09:51:54 +0100 Subject: [PATCH 1/2] Handle atomic expr --- cpp2rust/converter/rules/expr_matcher.cpp | 2 +- cpp2rust/converter/rules/rule_keys.cpp | 2 +- cpp2rust/converter/rules/rules_loader.cpp | 2 +- rules/stdatomic/src.c | 6 ++++++ rules/stdatomic/tgt_unsafe.rs | 6 ++++++ 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 rules/stdatomic/src.c create mode 100644 rules/stdatomic/tgt_unsafe.rs diff --git a/cpp2rust/converter/rules/expr_matcher.cpp b/cpp2rust/converter/rules/expr_matcher.cpp index 13b980485b..e244c861c4 100644 --- a/cpp2rust/converter/rules/expr_matcher.cpp +++ b/cpp2rust/converter/rules/expr_matcher.cpp @@ -75,7 +75,7 @@ using ResolvedDecl = ResolvedDecl getResolvedDecl(clang::ASTContext &ctx, const clang::Expr *expr, bool must_resolve) { expr = RuleDecls::SkipImplicit(expr); - if (llvm::isa(expr) && + if (llvm::isa(expr) && expr->getBeginLoc().isMacroID()) { return MacroUsage{ clang::Lexer::getImmediateMacroName( diff --git a/cpp2rust/converter/rules/rule_keys.cpp b/cpp2rust/converter/rules/rule_keys.cpp index adda286d3d..6a2e07322a 100644 --- a/cpp2rust/converter/rules/rule_keys.cpp +++ b/cpp2rust/converter/rules/rule_keys.cpp @@ -120,7 +120,7 @@ std::optional getDeclKey(const clang::NamedDecl *decl) { std::optional getExprKey(clang::ASTContext &ctx, const clang::Expr *expr) { expr = RuleDecls::SkipImplicit(expr); - if (llvm::isa(expr) && + if (llvm::isa(expr) && expr->getBeginLoc().isMacroID()) { auto macro = clang::Lexer::getImmediateMacroName( expr->getBeginLoc(), ctx.getSourceManager(), ctx.getLangOpts()); diff --git a/cpp2rust/converter/rules/rules_loader.cpp b/cpp2rust/converter/rules/rules_loader.cpp index d1b69f724c..4fbec807db 100644 --- a/cpp2rust/converter/rules/rules_loader.cpp +++ b/cpp2rust/converter/rules/rules_loader.cpp @@ -474,7 +474,7 @@ std::string DeclKey(const clang::NamedDecl *decl) { std::string ExprKey(clang::ASTContext &ctx, const clang::Expr *expr) { expr = expr->IgnoreParenImpCasts(); - if (llvm::isa(expr) && + if (llvm::isa(expr) && expr->getBeginLoc().isMacroID()) { return clang::Lexer::getImmediateMacroName( expr->getBeginLoc(), ctx.getSourceManager(), ctx.getLangOpts()) diff --git a/rules/stdatomic/src.c b/rules/stdatomic/src.c new file mode 100644 index 0000000000..85ebbf6e4c --- /dev/null +++ b/rules/stdatomic/src.c @@ -0,0 +1,6 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +void f1(volatile atomic_flag *a0) { return atomic_flag_clear(a0); } diff --git a/rules/stdatomic/tgt_unsafe.rs b/rules/stdatomic/tgt_unsafe.rs new file mode 100644 index 0000000000..e9384bfb84 --- /dev/null +++ b/rules/stdatomic/tgt_unsafe.rs @@ -0,0 +1,6 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +unsafe fn f1(a0: *mut ::std::sync::atomic::AtomicBool) { + (*a0).store(false, ::std::sync::atomic::Ordering::SeqCst) +} From 20647ec9d2a4340d17f5ac95c85b98ce2f8f10b8 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 10:21:27 +0100 Subject: [PATCH 2/2] Move stdatomic rule to C++ --- rules/stdatomic/{src.c => src_until_cxx23.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rules/stdatomic/{src.c => src_until_cxx23.cpp} (100%) diff --git a/rules/stdatomic/src.c b/rules/stdatomic/src_until_cxx23.cpp similarity index 100% rename from rules/stdatomic/src.c rename to rules/stdatomic/src_until_cxx23.cpp