https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/83065
>From 497b6639231f9d3141cc3278b3e476edd1d642d2 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser <nikolasklau...@berlin.de> Date: Tue, 27 Feb 2024 14:40:42 +0100 Subject: [PATCH] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 --- clang/docs/ReleaseNotes.rst | 1 + clang/test/Preprocessor/has_attribute.cpp | 4 +++- clang/test/SemaCXX/constant-expression-cxx11.cpp | 2 +- clang/test/SemaCXX/cxx03-cxx11-attr.cpp | 9 +++++++++ clang/utils/TableGen/ClangAttrEmitter.cpp | 12 +----------- 5 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 45ace4191592d3..4e0b28cb21ce27 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -267,6 +267,7 @@ Bug Fixes to C++ Support was only accepted at namespace scope but not at local function scope. - Clang no longer tries to call consteval constructors at runtime when they appear in a member initializer. (`#782154 <https://github.com/llvm/llvm-project/issues/82154>`_`) +- Fixes (`#82995 <https://github.com/llvm/llvm-project/issues/82995>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/test/Preprocessor/has_attribute.cpp b/clang/test/Preprocessor/has_attribute.cpp index 33546dbb175f61..00ec57615c84b8 100644 --- a/clang/test/Preprocessor/has_attribute.cpp +++ b/clang/test/Preprocessor/has_attribute.cpp @@ -1,4 +1,6 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM --implicit-check-not=: // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM --implicit-check-not=: +// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=: // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=: #define CXX11(x) x: __has_cpp_attribute(x) @@ -65,7 +67,7 @@ CXX11(unlikely) // CHECK: likely: 201803L // CHECK: maybe_unused: 201603L // ITANIUM: no_unique_address: 201803L -// WINDOWS: no_unique_address: 0 +// WINDOWS: no_unique_address: 0 // ITANIUM: msvc::no_unique_address: 0 // WINDOWS: msvc::no_unique_address: 201803L // CHECK: nodiscard: 201907L diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 9e2ae07cbe4c9c..e71659440aa11d 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only -verify=expected,cxx20_23,cxx23 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion +// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,cxx20_23,cxx23 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion // RUN: %clang_cc1 -std=c++20 -isystem %S/Inputs -fsyntax-only -verify=expected,cxx11_20,cxx20_23 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion // RUN: %clang_cc1 -std=c++11 -isystem %S/Inputs -fsyntax-only -verify=expected,cxx11_20,cxx11 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion diff --git a/clang/test/SemaCXX/cxx03-cxx11-attr.cpp b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp new file mode 100644 index 00000000000000..5a273c8fe2534a --- /dev/null +++ b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++03 -fsyntax-only %s + +// Ensure that __has_cpp_attribute and argument parsing work in C++03 + +#if !__has_cpp_attribute(nodiscard) +# error +#endif + +[[gnu::assume_aligned(4)]] void* g() { return __nullptr; } diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 935b9846990ee5..eb5c34d15693d7 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3576,10 +3576,6 @@ static void GenerateHasAttrSpellingStringSwitch( const Record *R = Attr->getValueAsDef("Target"); std::vector<StringRef> Arches = R->getValueAsListOfStrings("Arches"); GenerateTargetSpecificAttrChecks(R, Arches, Test, nullptr); - - // If this is the C++11 variety, also add in the LangOpts test. - if (Variety == "CXX11") - Test += " && LangOpts.CPlusPlus11"; } else if (!Attr->getValueAsListOfDefs("TargetSpecificSpellings").empty()) { // Add target checks if this spelling is target-specific. const std::vector<Record *> TargetSpellings = @@ -3597,13 +3593,7 @@ static void GenerateHasAttrSpellingStringSwitch( } } } - - if (Variety == "CXX11") - Test += " && LangOpts.CPlusPlus11"; - } else if (Variety == "CXX11") - // C++11 mode should be checked against LangOpts, which is presumed to be - // present in the caller. - Test = "LangOpts.CPlusPlus11"; + } std::string TestStr = !Test.empty() ? Test + " ? " + llvm::itostr(Version) + " : 0" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits