[clang] Always register `asm` attribute first in a Decl. (PR #162687)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 15:13:31 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,cpp,h -- clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDecl.cpp clang/test/Sema/attr-print.c
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cade2468b..3b4d6306d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3961,14 +3961,13 @@ public:
                                      bool &AddToScope,
                                      ArrayRef<BindingDecl *> Bindings = {});
 
-  private:
-
+private:
   // Perform a check on an AsmLabel to verify its consistency and emit
   // diagnostics in case of an error.
   void CheckAsmLabel(Scope *S, Expr *AsmLabelExpr, StorageClass SC,
                      TypeSourceInfo *TInfo, VarDecl *);
-  public:
 
+public:
   /// Perform semantic checking on a newly-created variable
   /// declaration.
   ///
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5a016e953..ac70158c3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7653,20 +7653,20 @@ void Sema::CheckAsmLabel(Scope *S, Expr *E, StorageClass SC,
   QualType R = TInfo->getType();
   if (S->getFnParent() != nullptr) {
     switch (SC) {
-      case SC_None:
-      case SC_Auto:
-        Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
-        break;
-      case SC_Register:
-        // Local Named register
-        if (!Context.getTargetInfo().isValidGCCRegisterName(Label) &&
-            DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl()))
-          Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
-        break;
-      case SC_Static:
-      case SC_Extern:
-      case SC_PrivateExtern:
-        break;
+    case SC_None:
+    case SC_Auto:
+      Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
+      break;
+    case SC_Register:
+      // Local Named register
+      if (!Context.getTargetInfo().isValidGCCRegisterName(Label) &&
+          DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl()))
+        Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
+      break;
+    case SC_Static:
+    case SC_Extern:
+    case SC_PrivateExtern:
+      break;
     }
   } else if (SC == SC_Register) {
     // Global Named register
@@ -7676,9 +7676,8 @@ void Sema::CheckAsmLabel(Scope *S, Expr *E, StorageClass SC,
 
       if (!TI.isValidGCCRegisterName(Label))
         Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
-      else if (!TI.validateGlobalRegisterVariable(Label,
-            Context.getTypeSize(R),
-            HasSizeMismatch))
+      else if (!TI.validateGlobalRegisterVariable(Label, Context.getTypeSize(R),
+                                                  HasSizeMismatch))
         Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label;
       else if (HasSizeMismatch)
         Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label;
@@ -7686,8 +7685,8 @@ void Sema::CheckAsmLabel(Scope *S, Expr *E, StorageClass SC,
 
     if (!R->isIntegralType(Context) && !R->isPointerType()) {
       Diag(TInfo->getTypeLoc().getBeginLoc(),
-          diag::err_asm_unsupported_register_type)
-        << TInfo->getTypeLoc().getSourceRange();
+           diag::err_asm_unsupported_register_type)
+          << TInfo->getTypeLoc().getSourceRange();
       NewVD->setInvalidDecl(true);
     }
   }
@@ -8185,15 +8184,15 @@ NamedDecl *Sema::ActOnVariableDeclarator(
     // Insert the asm attribute.
     NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0)));
   } else if (!ExtnameUndeclaredIdentifiers.empty()) {
-    llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
-      ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
+    llvm::DenseMap<IdentifierInfo *, AsmLabelAttr *>::iterator I =
+        ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
     if (I != ExtnameUndeclaredIdentifiers.end()) {
       if (isDeclExternC(NewVD)) {
         NewVD->addAttr(I->second);
         ExtnameUndeclaredIdentifiers.erase(I);
       } else
         Diag(NewVD->getLocation(), diag::warn_redefine_extname_not_applied)
-            << /*Variable*/1 << NewVD;
+            << /*Variable*/ 1 << NewVD;
     }
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/162687


More information about the cfe-commits mailing list