[llvm-branch-commits] [clang] [Clang][NFC] Pass Builtin::Info as an argument to Sema::BuildAtomicExpr (PR #185406)

Sameer Sahasrabuddhe via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 9 05:37:19 PDT 2026


https://github.com/ssahasra created https://github.com/llvm/llvm-project/pull/185406

Assisted-By: Claude Sonnet 4.5

>From 160a828b66c27d04f087caa808047066069d384a Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Mon, 9 Mar 2026 13:47:40 +0530
Subject: [PATCH] [Clang][NFC] Pass Builtin::Info as an argument to
 Sema::BuildAtomicExpr

Assisted-By: Claude Sonnet 4.5
---
 clang/include/clang/Basic/Builtins.h | 4 ++--
 clang/include/clang/Sema/Sema.h      | 4 +++-
 clang/lib/Sema/SemaChecking.cpp      | 9 ++++++---
 clang/lib/Sema/TreeTransform.h       | 2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.h b/clang/include/clang/Basic/Builtins.h
index 2e661419ac6dc..adb88684c7a1d 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -466,12 +466,12 @@ class Context {
     return strchr(getAttributesString(ID), 'G') != nullptr;
   }
 
+  const Info &getInfo(unsigned ID) const { return getShardAndInfo(ID).second; }
+
 private:
   std::pair<const InfosShard &, const Info &>
   getShardAndInfo(unsigned ID) const;
 
-  const Info &getInfo(unsigned ID) const { return getShardAndInfo(ID).second; }
-
   /// Helper function for isPrintfLike and isScanfLike.
   bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg,
               const char *Fmt) const;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5917eb0ffbfe1..ed5744bcd6962 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2738,6 +2738,7 @@ class Sema final : public SemaBase {
   BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
                   SourceLocation RParenLoc, MultiExprArg Args,
                   AtomicExpr::AtomicOp Op,
+                  const Builtin::Info *BuiltinInfo = nullptr,
                   AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API);
 
   /// Check to see if a given expression could have '.c_str()' called on it.
@@ -3032,7 +3033,8 @@ class Sema final : public SemaBase {
   /// builtins.
   ExprResult BuiltinNontemporalOverloaded(ExprResult TheCallResult);
   ExprResult AtomicOpsOverloaded(ExprResult TheCallResult,
-                                 AtomicExpr::AtomicOp Op);
+                                 AtomicExpr::AtomicOp Op,
+                                 const Builtin::Info *BuiltinInfo);
 
   /// \param FPOnly restricts the arguments to floating-point types.
   bool BuiltinElementwiseMath(CallExpr *TheCall,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 85aa21f2480fb..ba9890296ef96 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3210,7 +3210,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
   }
 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS, LANGS)                                 \
   case Builtin::BI##ID:                                                        \
-    return AtomicOpsOverloaded(TheCallResult, AtomicExpr::AO##ID);
+    return AtomicOpsOverloaded(TheCallResult, AtomicExpr::AO##ID,              \
+                               &Context.BuiltinInfo.getInfo(Builtin::BI##ID));
 #include "clang/Basic/Builtins.inc"
   case Builtin::BI__annotation:
     if (BuiltinMSVCAnnotation(*this, TheCall))
@@ -4558,18 +4559,20 @@ static bool isValidOrderingForOp(int64_t Ordering, AtomicExpr::AtomicOp Op) {
 }
 
 ExprResult Sema::AtomicOpsOverloaded(ExprResult TheCallResult,
-                                     AtomicExpr::AtomicOp Op) {
+                                     AtomicExpr::AtomicOp Op,
+                                     const Builtin::Info *BuiltinInfo) {
   CallExpr *TheCall = cast<CallExpr>(TheCallResult.get());
   DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
   MultiExprArg Args{TheCall->getArgs(), TheCall->getNumArgs()};
   return BuildAtomicExpr({TheCall->getBeginLoc(), TheCall->getEndLoc()},
                          DRE->getSourceRange(), TheCall->getRParenLoc(), Args,
-                         Op);
+                         Op, BuiltinInfo);
 }
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
                                  SourceLocation RParenLoc, MultiExprArg Args,
                                  AtomicExpr::AtomicOp Op,
+                                 const Builtin::Info *BuiltinInfo,
                                  AtomicArgumentOrder ArgOrder) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index b5272d262530c..9586df974b7ab 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4163,7 +4163,7 @@ class TreeTransform {
     // between the call and the expr at this point.
     SourceRange Range{BuiltinLoc, RParenLoc};
     return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
-                                     Sema::AtomicArgumentOrder::AST);
+                                     nullptr, Sema::AtomicArgumentOrder::AST);
   }
 
   ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc,



More information about the llvm-branch-commits mailing list