Skip to content

[Clang] Add missing macro undefs in AttributeSpellingList emitter #141090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

a-tarasyuk
Copy link
Member

Fixes #140629 (comment)


This patch adds #undef ATTR_NAME and #undef ATTR_SCOPE_NAME to the
end of the generated AttributeSpellingList.inc file to prevent macro
redefinition warnings

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 22, 2025
@llvmbot
Copy link
Member

llvmbot commented May 22, 2025

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #140629 (comment)


This patch adds #undef ATTR_NAME and #undef ATTR_SCOPE_NAME to the
end of the generated AttributeSpellingList.inc file to prevent macro
redefinition warnings


Full diff: https://github.com/llvm/llvm-project/pull/141090.diff

2 Files Affected:

  • (modified) clang/lib/Basic/Attributes.cpp (+1-3)
  • (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+7-3)
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index c2f3120aed5d0..ebc86a5adf7a7 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -233,13 +233,11 @@ unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
 static constexpr const char *AttrSpellingList[] = {
 #include "clang/Basic/AttributeSpellingList.inc"
 };
-#undef ATTR_NAME
 
-#define ATTR_SCOPE_SCOPE(SCOPE_NAME) SCOPE_NAME,
+#define ATTR_SCOPE_NAME(SCOPE_NAME) SCOPE_NAME,
 static constexpr const char *AttrScopeSpellingList[] = {
 #include "clang/Basic/AttributeSpellingList.inc"
 };
-#undef ATTR_SCOPE_SCOPE
 
 std::optional<std::string>
 AttributeCommonInfo::getCorrectedFullName(const TargetInfo &Target,
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index f6c5c84602762..21d76c12a3cce 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4146,14 +4146,18 @@ void EmitAttributeSpellingList(const RecordKeeper &Records, raw_ostream &OS) {
     OS << "ATTR_NAME(\"" << AttrName << "\")\n";
   }
   OS << "\n";
+  OS << "#undef ATTR_NAME" << "\n";
+  OS << "\n";
 
-  OS << "#ifndef ATTR_SCOPE_SCOPE" << "\n";
-  OS << "#define ATTR_SCOPE_SCOPE(SCOPE_NAME) SCOPE_NAME" << "\n";
+  OS << "#ifndef ATTR_SCOPE_NAME" << "\n";
+  OS << "#define ATTR_SCOPE_NAME(SCOPE_NAME) SCOPE_NAME" << "\n";
   OS << "#endif" << "\n" << "\n";
   for (const auto &AttrScopeName : AttrScopeSpellingList) {
-    OS << "ATTR_SCOPE_SCOPE(\"" << AttrScopeName << "\")\n";
+    OS << "ATTR_SCOPE_NAME(\"" << AttrScopeName << "\")\n";
   }
   OS << "\n";
+  OS << "#undef ATTR_SCOPE_NAME" << "\n";
+  OS << "\n";
 }
 
 static bool isArgVariadic(const Record &R, StringRef AttrName) {

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've verified that the warning goes away. Thank for fixing this quickly!

@thurstond
Copy link
Contributor

Could you please merge this to bring the buildbots back to green? Thanks!

@kazutakahirata kazutakahirata merged commit 00f40e3 into llvm:main May 22, 2025
14 checks passed
@kazutakahirata
Copy link
Contributor

Could you please merge this to bring the buildbots back to green? Thanks!

Done!

@thurstond
Copy link
Contributor

Could you please merge this to bring the buildbots back to green? Thanks!

Done!

Thank you!

sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…vm#141090)

Fixes
llvm#140629 (comment)

---

This patch adds `#undef ATTR_NAME` and `#undef ATTR_SCOPE_NAME` to the
end of the generated `AttributeSpellingList.inc` file to prevent macro
redefinition warnings
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
…vm#141090)

Fixes
llvm#140629 (comment)

---

This patch adds `#undef ATTR_NAME` and `#undef ATTR_SCOPE_NAME` to the
end of the generated `AttributeSpellingList.inc` file to prevent macro
redefinition warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants