https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/125796
>From 77ee45f25f03614dbb63369922e9722a79ec8518 Mon Sep 17 00:00:00 2001 From: Joseph Huber <hube...@outlook.com> Date: Tue, 4 Feb 2025 20:03:33 -0600 Subject: [PATCH 1/2] [Clang] Permit both `gnu` and `clang` prefixes on attributes Summary: Some attributes have gnu extensions that share names with clang attributes. If these imply the same thing, we can specially declare this to be an alternate but equivalent spelling. Discussions welcome on whether or not we want to bind ourselves to GNU behavior, since theoretically it's possible for GNU to silently change the semantics away from our implementation, but I'm not an expert. Fixes: https://github.com/llvm/llvm-project/issues/125760 --- clang/include/clang/Basic/Attr.td | 9 ++++++++- clang/test/SemaCXX/attr-no-sanitize.cpp | 4 ++-- clang/utils/TableGen/ClangAttrEmitter.cpp | 8 ++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 2a3a29bd2ee1cf4..4384a98d63eb3df 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -380,6 +380,13 @@ class Clang<string name, bit allowInC = 1, int version = 1> bit AllowInC = allowInC; } +// This spelling combines the spellings of GCC and Clang for cases where the +// spellings are equivalent for compile compatibility. +class ClangGCC<string name, bit allowInC = 1, int version = 1> + : Spelling<name, "ClangGCC", version> { + bit AllowInC = allowInC; +} + // HLSL Annotation spellings class HLSLAnnotation<string name> : Spelling<name, "HLSLAnnotation">; @@ -3677,7 +3684,7 @@ def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetAnyX86> } def NoSanitize : InheritableAttr { - let Spellings = [Clang<"no_sanitize">]; + let Spellings = [ClangGCC<"no_sanitize">]; let Args = [VariadicStringArgument<"Sanitizers">]; let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag>; let Documentation = [NoSanitizeDocs]; diff --git a/clang/test/SemaCXX/attr-no-sanitize.cpp b/clang/test/SemaCXX/attr-no-sanitize.cpp index 8951f616ce0f056..cd60e71963ac30a 100644 --- a/clang/test/SemaCXX/attr-no-sanitize.cpp +++ b/clang/test/SemaCXX/attr-no-sanitize.cpp @@ -21,8 +21,8 @@ int f3() __attribute__((no_sanitize("address"))); // DUMP-LABEL: FunctionDecl {{.*}} f4 // DUMP: NoSanitizeAttr {{.*}} hwaddress -// PRINT: {{\[\[}}clang::no_sanitize("hwaddress")]] int f4() -[[clang::no_sanitize("hwaddress")]] int f4(); +// PRINT: {{\[\[}}gnu::no_sanitize("hwaddress")]] int f4() +[[gnu::no_sanitize("hwaddress")]] int f4(); // DUMP-LABEL: FunctionDecl {{.*}} f5 // DUMP: NoSanitizeAttr {{.*}} address thread hwaddress diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index de12c7062666a45..af7478b7986f92b 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -108,6 +108,14 @@ GetFlattenedSpellings(const Record &Attr) { Ret.emplace_back("CXX11", Name, "clang", false, *Spelling); if (Spelling->getValueAsBit("AllowInC")) Ret.emplace_back("C23", Name, "clang", false, *Spelling); + } else if (Variety == "ClangGCC") { + Ret.emplace_back("GNU", Name, "", false, *Spelling); + Ret.emplace_back("CXX11", Name, "clang", false, *Spelling); + Ret.emplace_back("CXX11", Name, "gnu", false, *Spelling); + if (Spelling->getValueAsBit("AllowInC")) { + Ret.emplace_back("C23", Name, "clang", false, *Spelling); + Ret.emplace_back("C23", Name, "gnu", false, *Spelling); + } } else { Ret.push_back(FlattenedSpelling(*Spelling)); } >From 2baf79cb7fe951752cd244a89f864084343aa2bb Mon Sep 17 00:00:00 2001 From: Joseph Huber <hube...@outlook.com> Date: Wed, 5 Feb 2025 08:08:24 -0600 Subject: [PATCH 2/2] comments --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 90ba5e61d03fece..2979f3738a37730 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -110,6 +110,8 @@ Removed Compiler Flags Attribute Changes in Clang -------------------------- +- The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names. + Improvements to Clang's diagnostics ----------------------------------- _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits