[clang] `__noop` not marked as constexpr #102064 (PR #105983)
https://github.com/ofAlpaca created https://github.com/llvm/llvm-project/pull/105983 Resolves #102064 I think the problem is that the function `bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinOp)` return default `false` directly when visiting expression of `__noop`. Thus, `__noop` cannot be evaluated as constant initializer in here. https://github.com/llvm/llvm-project/blob/b6603e1bf11dee4761e49af6581c8b8f074b705d/clang/lib/Sema/SemaDecl.cpp#L14402 By adding a `BI__noop` case in `bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinOp)` should fix the problem. Correct me if there is anything I misunderstood. >From 7f13ff52821a6c2ba58236fe363fb9a3a378c33b Mon Sep 17 00:00:00 2001 From: ofAlpaca Date: Sun, 25 Aug 2024 17:02:11 +0800 Subject: [PATCH 1/3] Fix for GH102064 --- clang/include/clang/Basic/Builtins.td | 2 +- clang/lib/AST/ExprConstant.cpp| 4 clang/test/SemaCXX/GH102064.cpp | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/GH102064.cpp diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index f5b15cf90d1f83..b42f7ea1d9de68 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -2516,7 +2516,7 @@ def IsoVolatileStore : MSLangBuiltin, Int8_16_32_64Template { def Noop : MSLangBuiltin { let Spellings = ["__noop"]; - let Attributes = [NoThrow]; + let Attributes = [NoThrow, Constexpr]; let Prototype = "int(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5af712dd7257b1..d505346bccd9b3 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -12586,6 +12586,10 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, return false; } + case Builtin::BI__noop: + // __noop always evaluates successfully +return true; + case Builtin::BI__builtin_is_constant_evaluated: { const auto *Callee = Info.CurrentCall->getCallee(); if (Info.InConstantContext && !Info.CheckingPotentialConstantExpression && diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp new file mode 100644 index 00..52213b66e9eccc --- /dev/null +++ b/clang/test/SemaCXX/GH102064.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -std=c++20 -fms-extensions %s +// expected-no-diagnostics +constexpr int x = []{ __noop; return 0; }(); \ No newline at end of file >From 676b1b352d7e3279c6e3681466605e88b81dfdde Mon Sep 17 00:00:00 2001 From: ofAlpaca Date: Sun, 25 Aug 2024 20:03:19 +0800 Subject: [PATCH 2/3] Add release note --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 971df672b6ca1e..e60407061ccd3b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -861,6 +861,8 @@ Bug Fixes to Compiler Builtins - Clang now allows pointee types of atomic builtin arguments to be complete template types that was not instantiated elsewhere. +- Fix ``__noop`` not marked as constexpr. (#GH102064) + Bug Fixes to Attribute Support ^^ >From 9730d9c50033c44766b370ccc92de6575c1eca29 Mon Sep 17 00:00:00 2001 From: ofAlpaca Date: Sun, 25 Aug 2024 20:13:48 +0800 Subject: [PATCH 3/3] Update testcase for end of file newline --- clang/test/SemaCXX/GH102064.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp index 52213b66e9eccc..0ed930439e3d75 100644 --- a/clang/test/SemaCXX/GH102064.cpp +++ b/clang/test/SemaCXX/GH102064.cpp @@ -1,3 +1,3 @@ // RUN: %clang_cc1 -std=c++20 -fms-extensions %s // expected-no-diagnostics -constexpr int x = []{ __noop; return 0; }(); \ No newline at end of file +constexpr int x = []{ __noop; return 0; }(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] `__noop` not marked as constexpr #102064 (PR #105983)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/105983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] `__noop` not marked as constexpr #102064 (PR #105983)
llvmbot wrote: @llvm/pr-subscribers-clang Author: ofAlpaca (ofAlpaca) Changes Resolves #102064 I think the problem is that the function `bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinOp)` return default `false` directly when visiting expression of `__noop`. Thus, `__noop` cannot be evaluated as constant initializer in here. https://github.com/llvm/llvm-project/blob/b6603e1bf11dee4761e49af6581c8b8f074b705d/clang/lib/Sema/SemaDecl.cpp#L14402 By adding a `BI__noop` case in `bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinOp)` should fix the problem. Correct me if there is anything I misunderstood. --- Full diff: https://github.com/llvm/llvm-project/pull/105983.diff 4 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/include/clang/Basic/Builtins.td (+1-1) - (modified) clang/lib/AST/ExprConstant.cpp (+4) - (added) clang/test/SemaCXX/GH102064.cpp (+3) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 971df672b6ca1e..e60407061ccd3b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -861,6 +861,8 @@ Bug Fixes to Compiler Builtins - Clang now allows pointee types of atomic builtin arguments to be complete template types that was not instantiated elsewhere. +- Fix ``__noop`` not marked as constexpr. (#GH102064) + Bug Fixes to Attribute Support ^^ diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index f5b15cf90d1f83..b42f7ea1d9de68 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -2516,7 +2516,7 @@ def IsoVolatileStore : MSLangBuiltin, Int8_16_32_64Template { def Noop : MSLangBuiltin { let Spellings = ["__noop"]; - let Attributes = [NoThrow]; + let Attributes = [NoThrow, Constexpr]; let Prototype = "int(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5af712dd7257b1..d505346bccd9b3 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -12586,6 +12586,10 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, return false; } + case Builtin::BI__noop: + // __noop always evaluates successfully +return true; + case Builtin::BI__builtin_is_constant_evaluated: { const auto *Callee = Info.CurrentCall->getCallee(); if (Info.InConstantContext && !Info.CheckingPotentialConstantExpression && diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp new file mode 100644 index 00..0ed930439e3d75 --- /dev/null +++ b/clang/test/SemaCXX/GH102064.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -std=c++20 -fms-extensions %s +// expected-no-diagnostics +constexpr int x = []{ __noop; return 0; }(); `` https://github.com/llvm/llvm-project/pull/105983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1193f7d - [NFC] Use const members of `StringToOffsetTable` (#105824)
Author: Rahul Joshi Date: 2024-08-25T05:40:21-07:00 New Revision: 1193f7d6487d2d94009f8d8d27da3907136482b9 URL: https://github.com/llvm/llvm-project/commit/1193f7d6487d2d94009f8d8d27da3907136482b9 DIFF: https://github.com/llvm/llvm-project/commit/1193f7d6487d2d94009f8d8d27da3907136482b9.diff LOG: [NFC] Use const members of `StringToOffsetTable` (#105824) Added: Modified: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp llvm/utils/TableGen/AsmMatcherEmitter.cpp Removed: diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp index b290530444d2ab..6ca24a8c74b2ff 100644 --- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -1634,7 +1634,7 @@ static void emitDiagArrays(std::map &DiagsInGroup, /// \000\020#pragma-messages\t#warnings\020CFString-literal" /// }; /// \endcode -static void emitDiagGroupNames(StringToOffsetTable &GroupNames, +static void emitDiagGroupNames(const StringToOffsetTable &GroupNames, raw_ostream &OS) { OS << "static const char DiagGroupNames[] = {\n"; GroupNames.EmitString(OS); @@ -1656,7 +1656,7 @@ static void emitDiagGroupNames(StringToOffsetTable &GroupNames, static void emitAllDiagArrays(std::map &DiagsInGroup, RecordVec &DiagsInPedantic, RecordVec &GroupsInPedantic, - StringToOffsetTable &GroupNames, + const StringToOffsetTable &GroupNames, raw_ostream &OS) { OS << "\n#ifdef GET_DIAG_ARRAYS\n"; emitDiagArrays(DiagsInGroup, DiagsInPedantic, OS); @@ -1683,7 +1683,8 @@ static void emitAllDiagArrays(std::map &DiagsInGroup, static void emitDiagTable(std::map &DiagsInGroup, RecordVec &DiagsInPedantic, RecordVec &GroupsInPedantic, - StringToOffsetTable &GroupNames, raw_ostream &OS) { + const StringToOffsetTable &GroupNames, + raw_ostream &OS) { unsigned MaxLen = 0; for (auto const &I: DiagsInGroup) @@ -1705,7 +1706,7 @@ static void emitDiagTable(std::map &DiagsInGroup, OS << I.first << " */, "; // Store a pascal-style length byte at the beginning of the string. std::string Name = char(I.first.size()) + I.first; -OS << GroupNames.GetOrAddStringOffset(Name, false) << ", "; +OS << *GroupNames.GetStringOffset(Name) << ", "; // Special handling for 'pedantic'. const bool IsPedantic = I.first == "pedantic"; diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp index 5035ef52707f4e..98d0231d3055c2 100644 --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -2871,7 +2871,7 @@ static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, const AsmMatcherInfo &Info, StringRef ClassName, - StringToOffsetTable &StringTable, + const StringToOffsetTable &StringTable, unsigned MaxMnemonicIndex, unsigned MaxFeaturesIndex, bool HasMnemonicFirst, const Record &AsmParser) { unsigned MaxMask = 0; @@ -2924,8 +2924,8 @@ emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, // Store a pascal-style length byte in the mnemonic. std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.lower(); -OS << StringTable.GetOrAddStringOffset(LenMnemonic, false) << " /* " - << II.Mnemonic << " */, "; +OS << *StringTable.GetStringOffset(LenMnemonic) << " /* " << II.Mnemonic + << " */, "; OS << OMI.OperandMask; OS << " /* "; @@ -3554,8 +3554,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { // Store a pascal-style length byte in the mnemonic. std::string LenMnemonic = char(MI->Mnemonic.size()) + MI->Mnemonic.lower(); - OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) - << " /* " << MI->Mnemonic << " */, " << Target.getInstNamespace() + OS << " { " << *StringTable.GetStringOffset(LenMnemonic) << " /* " + << MI->Mnemonic << " */, " << Target.getInstNamespace() << "::" << MI->getResultInst()->TheDef->getName() << ", " << MI->ConversionFnKind << ", "; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NFC] Use const members of `StringToOffsetTable` (PR #105824)
https://github.com/jurahul closed https://github.com/llvm/llvm-project/pull/105824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)
yronglin wrote: friendly ping~ https://github.com/llvm/llvm-project/pull/97308 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NFC] Use const members of `StringToOffsetTable` (PR #105824)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` running on `sanitizer-buildbot2` while building `clang,llvm` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/3089 Here is the relevant piece of the build log for the reference: ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... [373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o [374/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o [375/378] Generating Msan-x86_64-with-call-Test [376/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o [377/378] Generating Msan-x86_64-Test [377/378] Running compiler_rt regression tests llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276: warning: input '/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/rtsan/X86_64LinuxConfig' contained no tests llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 4506 of 10211 tests, 88 workers -- Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60 FAIL: SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp (2957 of 4506) TEST 'SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 2: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp + /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp RUN: at line 5: env LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1 /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp 2>&1 | FileCheck /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -check-prefix=CHECK_MAY_RETURN_1 + env LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1 /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp + FileCheck /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -check-prefix=CHECK_MAY_RETURN_1 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp:68:24: error: CHECK_MAY_RETURN_1: expected string not found in input // CHECK_MAY_RETURN_1: allocating 512 times ^ :52:44: note: scanning from here Some of the malloc calls returned non-null: 256 ^ :53:14: note: possible intended match here ==1509716==LeakSanitizer: soft rss limit unexhausted (220Mb vs 119Mb) ^ Input file: Check file: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -dump-input=help explains the following input dump. Input was: << . . . 47: [256] 48: [320] 49: [384] 50: [448] 51: Some of the malloc calls returned null: 256 52: Some of the malloc calls returned non-null: 256 check:68'0X error: no match found 53: ==1509716==LeakSanitizer: soft rss limit unexhausted (220Mb vs 119Mb) Step 11 (test compiler-rt debug) failure: test compiler-rt debug (failure) ... [373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o [374/378] Generating MSAN_INST_TEST_OBJECTS.msan
[clang-tools-extra] [clang-tidy] Use upper case letters for bool conversion suffix (PR #104882)
https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/104882 >From 8a4f6af9fc1f44c2f8b5fd3693ca14eaf776fd02 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Sun, 11 Aug 2024 21:39:35 +0100 Subject: [PATCH 01/14] [clang-tidy] use upper cace letters for bool conversion suffix When readability-implicit-bool-conversion-check and readability-uppercase-literal-suffix-check is enabled this will cause you to apply a fix twice from (!i) -> (i == 0u) to (i == 0U) twice instead will skip the middle one --- .../readability/ImplicitBoolConversionCheck.cpp | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index aa115cd450c4f6..258cec80dd0bac 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -43,10 +43,10 @@ StringRef getZeroLiteralToCompareWithForType(CastKind CastExprKind, ASTContext &Context) { switch (CastExprKind) { case CK_IntegralToBoolean: -return Type->isUnsignedIntegerType() ? "0u" : "0"; +return Type->isUnsignedIntegerType() ? "0U" : "0"; case CK_FloatingToBoolean: -return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0"; +return Context.hasSameType(Type, Context.FloatTy) ? "0.0F" : "0.0"; case CK_PointerToBoolean: case CK_MemberPointerToBoolean: // Fall-through on purpose. @@ -202,13 +202,13 @@ StringRef getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral, if (DestType->isFloatingType()) { if (Context.hasSameType(DestType, Context.FloatTy)) { - return BoolLiteral->getValue() ? "1.0f" : "0.0f"; + return BoolLiteral->getValue() ? "1.0F" : "0.0F"; } return BoolLiteral->getValue() ? "1.0" : "0.0"; } if (DestType->isUnsignedIntegerType()) { -return BoolLiteral->getValue() ? "1u" : "0u"; +return BoolLiteral->getValue() ? "1U" : "0U"; } return BoolLiteral->getValue() ? "1" : "0"; } >From efb102b86e6ba2d05141040faf31eaaff5886f18 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Tue, 13 Aug 2024 00:49:41 +0100 Subject: [PATCH 02/14] Update test cases --- .../readability/implicit-bool-conversion.c| 14 +- .../readability/implicit-bool-conversion.cpp | 28 +-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c index a8c69858f76b61..29869b100894f4 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c @@ -94,7 +94,7 @@ void implicitConversionFromBoolLiterals() { functionTakingUnsignedLong(false); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: implicit conversion 'bool' -> 'unsigned long' - // CHECK-FIXES: functionTakingUnsignedLong(0u); + // CHECK-FIXES: functionTakingUnsignedLong(0U); functionTakingSignedChar(true); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: implicit conversion 'bool' -> 'signed char' @@ -102,7 +102,7 @@ void implicitConversionFromBoolLiterals() { functionTakingFloat(false); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: implicit conversion 'bool' -> 'float' - // CHECK-FIXES: functionTakingFloat(0.0f); + // CHECK-FIXES: functionTakingFloat(0.0F); functionTakingDouble(true); // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'bool' -> 'double' @@ -159,12 +159,12 @@ void implicitConversionToBoolSimpleCases() { unsigned long unsignedLong = 10; functionTakingBool(unsignedLong); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: implicit conversion 'unsigned long' -> 'bool' - // CHECK-FIXES: functionTakingBool(unsignedLong != 0u); + // CHECK-FIXES: functionTakingBool(unsignedLong != 0U); float floating = 0.0f; functionTakingBool(floating); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: implicit conversion 'float' -> 'bool' - // CHECK-FIXES: functionTakingBool(floating != 0.0f); + // CHECK-FIXES: functionTakingBool(floating != 0.0F); double doubleFloating = 1.0f; functionTakingBool(doubleFloating); @@ -193,7 +193,7 @@ void implicitConversionToBoolInSingleExpressions() { bool boolComingFromFloat; boolComingFromFloat = floating; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion 'float' -> 'bool' - // CHECK-FIXES: boolComingFromFloat = (floating != 0.0f); + // CHECK-FIXES: boolComingFromFloat = (floating != 0.0F); signed char character = 'a'; bool boolComingFromChar; @@ -231,7 +231,7 @@ bool implicitConversionToBoolInReturnValue() { float floating = 1.0f; return float
[clang] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] [polly] python: use raw strings for regex (PR #105990)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/105990 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] [polly] python: use raw strings for regex (PR #105990)
llvmbot wrote: @llvm/pr-subscribers-libcxx Author: Paul Zander (negril) Changes Changed in python version 3.12: A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+\. \d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+\.\d+")). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.) Closes: https://github.com/llvm/llvm-project/issues/97815 See-also: https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences --- Patch is 123.19 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/105990.diff 98 Files Affected: - (modified) .github/workflows/version-check.py (+1-1) - (modified) clang/docs/tools/dump_ast_matchers.py (+2-2) - (modified) clang/test/Analysis/check-analyzer-fixit.py (+1-1) - (modified) compiler-rt/lib/asan/scripts/asan_symbolize.py (+2-2) - (modified) cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py (+2-2) - (modified) cross-project-tests/lit.cfg.py (+3-3) - (modified) libcxx/utils/synchronize_csv_status_files.py (+1-1) - (modified) lld/test/MachO/tools/validate-unwind-info.py (+1-1) - (modified) lld/utils/benchmark.py (+1-1) - (modified) lldb/examples/python/crashlog.py (+4-4) - (modified) lldb/examples/python/delta.py (+1-1) - (modified) lldb/examples/python/gdbremote.py (+3-3) - (modified) lldb/examples/python/jump.py (+3-3) - (modified) lldb/examples/python/performance.py (+1-1) - (modified) lldb/examples/python/symbolication.py (+3-3) - (modified) lldb/packages/Python/lldbsuite/test/lldbpexpect.py (+1-1) - (modified) lldb/packages/Python/lldbsuite/test/test_runner/process_control.py (+1-1) - (modified) lldb/test/API/commands/command/backticks/TestBackticksInAlias.py (+2-2) - (modified) lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py (+1-1) - (modified) lldb/test/API/commands/expression/test/TestExprs.py (+1-1) - (modified) lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py (+1-1) - (modified) lldb/test/API/commands/help/TestHelp.py (+3-3) - (modified) lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py (+1-1) - (modified) lldb/test/API/commands/register/register/TestRegistersUnavailable.py (+2-2) - (modified) lldb/test/API/commands/register/register/register_command/TestRegisters.py (+3-3) - (modified) lldb/test/API/commands/settings/TestSettings.py (+6-6) - (modified) lldb/test/API/commands/target/basic/TestTargetCommand.py (+1-1) - (modified) lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py (+8-8) - (modified) lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py (+8-8) - (modified) lldb/test/API/commands/trace/TestTraceDumpInfo.py (+1-1) - (modified) lldb/test/API/commands/trace/TestTraceTSC.py (+5-5) - (modified) lldb/test/API/driver/quit_speed/TestQuitWithProcess.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py (+3-3) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py (+3-3) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py (+8-8) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py (+11-11) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/TestInitializerList.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py (+2-2) - (modified) lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py (+5-5) - (modified) lldb/test/API/functionalities/memory-region/TestMemoryRegion.py (+1-1) - (modified) lldb/test/API/functionalities/target_var/TestTargetVar.py (+1-1) - (modified) lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py (+1-1) - (modified) lldb/test/API/lang/c/enum_types/TestEnumTypes.py (+2-2) - (modified) lldb/test/API/lang/c/function_types/TestFunctionTypes.py (+1-1) - (modified) lldb/test/API/lang/c/register_variables/TestRegisterVariables.py (+1-1) - (modi
[clang] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] [polly] python: use raw strings for regex (PR #105990)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Paul Zander (negril) Changes Changed in python version 3.12: A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+\. \d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+\.\d+")). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.) Closes: https://github.com/llvm/llvm-project/issues/97815 See-also: https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences --- Patch is 123.19 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/105990.diff 98 Files Affected: - (modified) .github/workflows/version-check.py (+1-1) - (modified) clang/docs/tools/dump_ast_matchers.py (+2-2) - (modified) clang/test/Analysis/check-analyzer-fixit.py (+1-1) - (modified) compiler-rt/lib/asan/scripts/asan_symbolize.py (+2-2) - (modified) cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py (+2-2) - (modified) cross-project-tests/lit.cfg.py (+3-3) - (modified) libcxx/utils/synchronize_csv_status_files.py (+1-1) - (modified) lld/test/MachO/tools/validate-unwind-info.py (+1-1) - (modified) lld/utils/benchmark.py (+1-1) - (modified) lldb/examples/python/crashlog.py (+4-4) - (modified) lldb/examples/python/delta.py (+1-1) - (modified) lldb/examples/python/gdbremote.py (+3-3) - (modified) lldb/examples/python/jump.py (+3-3) - (modified) lldb/examples/python/performance.py (+1-1) - (modified) lldb/examples/python/symbolication.py (+3-3) - (modified) lldb/packages/Python/lldbsuite/test/lldbpexpect.py (+1-1) - (modified) lldb/packages/Python/lldbsuite/test/test_runner/process_control.py (+1-1) - (modified) lldb/test/API/commands/command/backticks/TestBackticksInAlias.py (+2-2) - (modified) lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py (+1-1) - (modified) lldb/test/API/commands/expression/test/TestExprs.py (+1-1) - (modified) lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py (+1-1) - (modified) lldb/test/API/commands/help/TestHelp.py (+3-3) - (modified) lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py (+1-1) - (modified) lldb/test/API/commands/register/register/TestRegistersUnavailable.py (+2-2) - (modified) lldb/test/API/commands/register/register/register_command/TestRegisters.py (+3-3) - (modified) lldb/test/API/commands/settings/TestSettings.py (+6-6) - (modified) lldb/test/API/commands/target/basic/TestTargetCommand.py (+1-1) - (modified) lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py (+8-8) - (modified) lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py (+8-8) - (modified) lldb/test/API/commands/trace/TestTraceDumpInfo.py (+1-1) - (modified) lldb/test/API/commands/trace/TestTraceTSC.py (+5-5) - (modified) lldb/test/API/driver/quit_speed/TestQuitWithProcess.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py (+3-3) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py (+3-3) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py (+8-8) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py (+11-11) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/TestInitializerList.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py (+2-2) - (modified) lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py (+5-5) - (modified) lldb/test/API/functionalities/memory-region/TestMemoryRegion.py (+1-1) - (modified) lldb/test/API/functionalities/target_var/TestTargetVar.py (+1-1) - (modified) lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py (+1-1) - (modified) lldb/test/API/lang/c/enum_types/TestEnumTypes.py (+2-2) - (modified) lldb/test/API/lang/c/function_types/TestFunctionTypes.py (+1-1) - (modified) lldb/test/API/lang/c/register_variables/TestRegisterVariables.py (+1-1) - (modif
[clang-tools-extra] [clang-tidy] Use upper case letters for bool conversion suffix (PR #104882)
https://github.com/carlosgalvezp approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/104882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/105996 None >From 0e4c511107f76da085a8019cf2eca78c3a5a0754 Mon Sep 17 00:00:00 2001 From: yronglin Date: Mon, 26 Aug 2024 02:09:31 +0800 Subject: [PATCH] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! Signed-off-by: yronglin --- clang/include/clang/AST/ASTContext.h | 8 + clang/include/clang/Sema/Sema.h | 8 - clang/lib/AST/ASTContext.cpp | 50 +++ clang/lib/AST/ByteCode/Compiler.cpp | 141 ++ clang/lib/AST/ByteCode/Compiler.h | 6 + clang/lib/Sema/SemaChecking.cpp | 2 +- clang/lib/Sema/SemaExpr.cpp | 67 + clang/test/AST/ByteCode/constexpr-vectors.cpp | 88 +++ 8 files changed, 300 insertions(+), 70 deletions(-) create mode 100644 clang/test/AST/ByteCode/constexpr-vectors.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 58a820508da42b..01dbf62a3db88c 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1558,6 +1558,14 @@ class ASTContext : public RefCountedBase { /// Return a WebAssembly externref type. QualType getWebAssemblyExternrefType() const; + /// Return a signed ext_vector_type that is of identical size and number of + /// elements. For floating point vectors, return an integer type of identical + /// size and number of elements. In the non ext_vector_type case, search from + /// the largest type to the smallest type to avoid cases where long long == + /// long, where long gets picked over long long. + QualType GetSignedVectorType(QualType V); + QualType GetSignedSizelessVectorType(QualType V); + /// Return the unique reference to a vector type of the specified /// element type and size. /// diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1f7e555d1b8717..dd637ef3dd822b 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7393,14 +7393,6 @@ class Sema final : public SemaBase { bool AllowBothBool, bool AllowBoolConversion, bool AllowBoolOperation, bool ReportInvalid); - /// Return a signed ext_vector_type that is of identical size and number of - /// elements. For floating point vectors, return an integer type of identical - /// size and number of elements. In the non ext_vector_type case, search from - /// the largest type to the smallest type to avoid cases where long long == - /// long, where long gets picked over long long. - QualType GetSignedVectorType(QualType V); - QualType GetSignedSizelessVectorType(QualType V); - /// CheckVectorCompareOperands - vector comparisons are a clang extension that /// operates on extended vector types. Instead of producing an IntTy result, /// like a scalar comparison, a vector comparison produces a vector of integer diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b201d201e1ea6a..408d4b006a7469 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -,6 +,56 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts, return QualType(); } +QualType ASTContext::GetSignedVectorType(QualType V) { + const VectorType *VTy = V->castAs(); + unsigned TypeSize = getTypeSize(VTy->getElementType()); + + if (isa(VTy)) { +if (VTy->isExtVectorBoolType()) + return getExtVectorType(BoolTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(CharTy)) + return getExtVectorType(CharTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(ShortTy)) + return getExtVectorType(ShortTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(IntTy)) + return getExtVectorType(IntTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(Int128Ty)) + return getExtVectorType(Int128Ty, VTy->getNumElements()); +if (TypeSize == getTypeSize(LongTy)) + return getExtVectorType(LongTy, VTy->getNumElements()); +assert(TypeSize == getTypeSize(LongLongTy) && + "Unhandled vector element size in vector compare"); +return getExtVectorType(LongLongTy, VTy->getNumElements()); + } + + if (TypeSize == getTypeSize(Int128Ty)) +return getVectorType(Int128Ty, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(LongLongTy)) +return getVectorType(LongLongTy, VTy->getNumElements(), + VectorKind::Generic); + if (TypeSize == getTypeSize(LongTy)) +return getVectorType(LongTy, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(IntTy)) +return getVectorType(IntTy, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(ShortTy)) +return getVectorType(ShortTy, VTy->getNumElements(), VectorKind::Generic); + assert(TypeSize == ge
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (yronglin) Changes --- Patch is 22.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/105996.diff 8 Files Affected: - (modified) clang/include/clang/AST/ASTContext.h (+8) - (modified) clang/include/clang/Sema/Sema.h (-8) - (modified) clang/lib/AST/ASTContext.cpp (+50) - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+141) - (modified) clang/lib/AST/ByteCode/Compiler.h (+6) - (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) - (modified) clang/lib/Sema/SemaExpr.cpp (+6-61) - (added) clang/test/AST/ByteCode/constexpr-vectors.cpp (+88) ``diff diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 58a820508da42b..01dbf62a3db88c 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1558,6 +1558,14 @@ class ASTContext : public RefCountedBase { /// Return a WebAssembly externref type. QualType getWebAssemblyExternrefType() const; + /// Return a signed ext_vector_type that is of identical size and number of + /// elements. For floating point vectors, return an integer type of identical + /// size and number of elements. In the non ext_vector_type case, search from + /// the largest type to the smallest type to avoid cases where long long == + /// long, where long gets picked over long long. + QualType GetSignedVectorType(QualType V); + QualType GetSignedSizelessVectorType(QualType V); + /// Return the unique reference to a vector type of the specified /// element type and size. /// diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1f7e555d1b8717..dd637ef3dd822b 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7393,14 +7393,6 @@ class Sema final : public SemaBase { bool AllowBothBool, bool AllowBoolConversion, bool AllowBoolOperation, bool ReportInvalid); - /// Return a signed ext_vector_type that is of identical size and number of - /// elements. For floating point vectors, return an integer type of identical - /// size and number of elements. In the non ext_vector_type case, search from - /// the largest type to the smallest type to avoid cases where long long == - /// long, where long gets picked over long long. - QualType GetSignedVectorType(QualType V); - QualType GetSignedSizelessVectorType(QualType V); - /// CheckVectorCompareOperands - vector comparisons are a clang extension that /// operates on extended vector types. Instead of producing an IntTy result, /// like a scalar comparison, a vector comparison produces a vector of integer diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b201d201e1ea6a..408d4b006a7469 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -,6 +,56 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts, return QualType(); } +QualType ASTContext::GetSignedVectorType(QualType V) { + const VectorType *VTy = V->castAs(); + unsigned TypeSize = getTypeSize(VTy->getElementType()); + + if (isa(VTy)) { +if (VTy->isExtVectorBoolType()) + return getExtVectorType(BoolTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(CharTy)) + return getExtVectorType(CharTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(ShortTy)) + return getExtVectorType(ShortTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(IntTy)) + return getExtVectorType(IntTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(Int128Ty)) + return getExtVectorType(Int128Ty, VTy->getNumElements()); +if (TypeSize == getTypeSize(LongTy)) + return getExtVectorType(LongTy, VTy->getNumElements()); +assert(TypeSize == getTypeSize(LongLongTy) && + "Unhandled vector element size in vector compare"); +return getExtVectorType(LongLongTy, VTy->getNumElements()); + } + + if (TypeSize == getTypeSize(Int128Ty)) +return getVectorType(Int128Ty, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(LongLongTy)) +return getVectorType(LongLongTy, VTy->getNumElements(), + VectorKind::Generic); + if (TypeSize == getTypeSize(LongTy)) +return getVectorType(LongTy, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(IntTy)) +return getVectorType(IntTy, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(ShortTy)) +return getVectorType(ShortTy, VTy->getNumElements(), VectorKind::Generic); + assert(TypeSize == getTypeSize(CharTy) && + "Unhandled vector element size in vector compare"); + return getVectorType(CharTy, VTy->getNumElements(), VectorKind::Generic); +} + +QualType ASTContext::GetSignedSizelessVectorType(QualType V) { + const BuiltinType *VTy = V->c
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
https://github.com/yronglin updated https://github.com/llvm/llvm-project/pull/105996 >From 0e4c511107f76da085a8019cf2eca78c3a5a0754 Mon Sep 17 00:00:00 2001 From: yronglin Date: Mon, 26 Aug 2024 02:09:31 +0800 Subject: [PATCH 1/2] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! Signed-off-by: yronglin --- clang/include/clang/AST/ASTContext.h | 8 + clang/include/clang/Sema/Sema.h | 8 - clang/lib/AST/ASTContext.cpp | 50 +++ clang/lib/AST/ByteCode/Compiler.cpp | 141 ++ clang/lib/AST/ByteCode/Compiler.h | 6 + clang/lib/Sema/SemaChecking.cpp | 2 +- clang/lib/Sema/SemaExpr.cpp | 67 + clang/test/AST/ByteCode/constexpr-vectors.cpp | 88 +++ 8 files changed, 300 insertions(+), 70 deletions(-) create mode 100644 clang/test/AST/ByteCode/constexpr-vectors.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 58a820508da42b..01dbf62a3db88c 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1558,6 +1558,14 @@ class ASTContext : public RefCountedBase { /// Return a WebAssembly externref type. QualType getWebAssemblyExternrefType() const; + /// Return a signed ext_vector_type that is of identical size and number of + /// elements. For floating point vectors, return an integer type of identical + /// size and number of elements. In the non ext_vector_type case, search from + /// the largest type to the smallest type to avoid cases where long long == + /// long, where long gets picked over long long. + QualType GetSignedVectorType(QualType V); + QualType GetSignedSizelessVectorType(QualType V); + /// Return the unique reference to a vector type of the specified /// element type and size. /// diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1f7e555d1b8717..dd637ef3dd822b 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7393,14 +7393,6 @@ class Sema final : public SemaBase { bool AllowBothBool, bool AllowBoolConversion, bool AllowBoolOperation, bool ReportInvalid); - /// Return a signed ext_vector_type that is of identical size and number of - /// elements. For floating point vectors, return an integer type of identical - /// size and number of elements. In the non ext_vector_type case, search from - /// the largest type to the smallest type to avoid cases where long long == - /// long, where long gets picked over long long. - QualType GetSignedVectorType(QualType V); - QualType GetSignedSizelessVectorType(QualType V); - /// CheckVectorCompareOperands - vector comparisons are a clang extension that /// operates on extended vector types. Instead of producing an IntTy result, /// like a scalar comparison, a vector comparison produces a vector of integer diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b201d201e1ea6a..408d4b006a7469 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -,6 +,56 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts, return QualType(); } +QualType ASTContext::GetSignedVectorType(QualType V) { + const VectorType *VTy = V->castAs(); + unsigned TypeSize = getTypeSize(VTy->getElementType()); + + if (isa(VTy)) { +if (VTy->isExtVectorBoolType()) + return getExtVectorType(BoolTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(CharTy)) + return getExtVectorType(CharTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(ShortTy)) + return getExtVectorType(ShortTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(IntTy)) + return getExtVectorType(IntTy, VTy->getNumElements()); +if (TypeSize == getTypeSize(Int128Ty)) + return getExtVectorType(Int128Ty, VTy->getNumElements()); +if (TypeSize == getTypeSize(LongTy)) + return getExtVectorType(LongTy, VTy->getNumElements()); +assert(TypeSize == getTypeSize(LongLongTy) && + "Unhandled vector element size in vector compare"); +return getExtVectorType(LongLongTy, VTy->getNumElements()); + } + + if (TypeSize == getTypeSize(Int128Ty)) +return getVectorType(Int128Ty, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(LongLongTy)) +return getVectorType(LongLongTy, VTy->getNumElements(), + VectorKind::Generic); + if (TypeSize == getTypeSize(LongTy)) +return getVectorType(LongTy, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(IntTy)) +return getVectorType(IntTy, VTy->getNumElements(), VectorKind::Generic); + if (TypeSize == getTypeSize(ShortTy)) +return getVectorType(ShortTy, VTy->getNumElements(), VectorKind::Generic); + assert(TypeSize == getT
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
https://github.com/yronglin edited https://github.com/llvm/llvm-project/pull/105996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 5c94dd73b2df1f6b469e858ff29055ac117e8494 0e4c511107f76da085a8019cf2eca78c3a5a0754 --extensions cpp,h -- clang/test/AST/ByteCode/constexpr-vectors.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Compiler.h clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index fa329fa8cc..48f177d4d9 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5316,7 +5316,7 @@ bool Compiler::VisitComplexUnaryOperator(const UnaryOperator *E) { template bool Compiler::VisitVectorUnaryOp(const UnaryOperator *E) { -const Expr *SubExpr = E->getSubExpr(); + const Expr *SubExpr = E->getSubExpr(); assert(SubExpr->getType()->isVectorType()); if (DiscardResult) @@ -5374,10 +5374,13 @@ bool Compiler::VisitVectorUnaryOp(const UnaryOperator *E) { if (!createTemp()) return false; -// In C++, the logic operators !, &&, || are available for vectors. !v is equivalent to v == 0. -// https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html -QualType SignedVecT = Ctx.getASTContext().GetSignedVectorType(SubExpr->getType()); -PrimType SignedElemT = classifyPrim(SignedVecT->getAs()->getElementType()); +// In C++, the logic operators !, &&, || are available for vectors. !v is +// equivalent to v == 0. +// https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html +QualType SignedVecT = +Ctx.getASTContext().GetSignedVectorType(SubExpr->getType()); +PrimType SignedElemT = +classifyPrim(SignedVecT->getAs()->getElementType()); for (unsigned I = 0; I != VecT->getNumElements(); ++I) { if (!getElem(SubExprOffset, I)) return false; @@ -5393,13 +5396,14 @@ bool Compiler::VisitVectorUnaryOp(const UnaryOperator *E) { if (!this->emitNeg(ElemT, E)) return false; if (ElemT != SignedElemT && - !this->emitPrimCast(ElemT, SignedElemT, SignedVecT, E)) -return false; +!this->emitPrimCast(ElemT, SignedElemT, SignedVecT, E)) + return false; } else { -// Float types result in an int of the same size, but -1 for true, or 0 for -// false. +// Float types result in an int of the same size, but -1 for true, or 0 +// for false. auto &FpSemantics = Ctx.getFloatSemantics(VecT->getElementType()); -unsigned NumBits = Ctx.getBitWidth(SignedVecT->getAs()->getElementType()); +unsigned NumBits = +Ctx.getBitWidth(SignedVecT->getAs()->getElementType()); auto Zero = APFloat::getZero(FpSemantics); APSInt SIntZero(APSInt::getZero(NumBits)); APSInt SIntAllOne(APSInt::getAllOnes(NumBits)); `` https://github.com/llvm/llvm-project/pull/105996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
https://github.com/yronglin edited https://github.com/llvm/llvm-project/pull/105996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
https://github.com/yronglin edited https://github.com/llvm/llvm-project/pull/105996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)
@@ -4806,6 +4806,34 @@ getOverflowPatternBinOp(const BinaryOperator *E) { return {}; } +/// Compute and set the OverflowPatternExclusion bit based on whether the JustinStitt wrote: I wanted to avoid calling `getOverflowPatternBinOp()` as it is more expensive than just checking if the flags are enabled or not. https://github.com/llvm/llvm-project/pull/105709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/105709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (PR #105999)
https://github.com/MaxEW707 created https://github.com/llvm/llvm-project/pull/105999 Fixes https://github.com/llvm/llvm-project/pull/104722. Missed handling `decltype(auto)` trailing return types for lambdas. This was a mistake and regression on my part with my PR, https://github.com/llvm/llvm-project/pull/104722. Added some missing unit tests to test for the various placeholder trailing return types in lambdas. >From ede0f3260ff728cc2c5ded867917b2f909d5c690 Mon Sep 17 00:00:00 2001 From: MaxEW707 Date: Sun, 25 Aug 2024 11:38:26 -0700 Subject: [PATCH] Fix MS 1920+ placeholder return type mangling for lambdas --- clang/lib/AST/MicrosoftMangle.cpp | 7 +++ clang/test/CodeGenCXX/mangle-ms-auto-return.cpp | 14 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index b539681984ef7c..018ab617a0ecee 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -2967,13 +2967,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, mangleType(ResultType, Range, QMM_Result); } else if (IsInLambda) { if (const auto *AT = ResultType->getContainedAutoType()) { -assert(AT->getKeyword() == AutoTypeKeyword::Auto && - "should only need to mangle auto!"); -(void)AT; +assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType && + "shouldn't need to mangle __auto_type!"); Out << '?'; mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false); Out << '?'; -mangleSourceName(""); +mangleSourceName(AT->isDecltypeAuto() ? "" : ""); Out << '@'; } else { Out << '@'; diff --git a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp index 5b18dcc0820ee6..0cf59ac962a764 100644 --- a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp +++ b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp @@ -215,6 +215,8 @@ void test_template_decltypeauto() { // Still want to use clang's custom mangling for lambdas to keep backwards compatibility until // MSVC lambda name mangling has been deciphered. void test_lambda() { + int i = 0; + auto lambdaIntRetAuto = []() { return 0; }; lambdaIntRetAuto(); // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" @@ -226,6 +228,18 @@ void test_lambda() { auto lambdaGenericIntIntRetAuto = [](auto a) { return a; }; lambdaGenericIntIntRetAuto(0); // CHECK: call {{.*}} @"??$?RH@@?0??test_lambda@@YAXXZ@QEBA?A?@@H@Z" + + auto lambdaRetTrailingAuto = []() -> auto { return 0; }; + lambdaRetTrailingAuto(); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" + + auto lambdaRetTrailingDecltypeAuto = []() -> decltype(auto) { return 0; }; + lambdaRetTrailingDecltypeAuto(); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" + + auto lambdaRetTrailingRefCollapse = [](int x) -> auto&& { return x; }; + lambdaRetTrailingRefCollapse(i); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@H@Z" } auto TestTrailingInt() -> int { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (PR #105999)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Max Winkler (MaxEW707) Changes Fixes https://github.com/llvm/llvm-project/pull/104722. Missed handling `decltype(auto)` trailing return types for lambdas. This was a mistake and regression on my part with my PR, https://github.com/llvm/llvm-project/pull/104722. Added some missing unit tests to test for the various placeholder trailing return types in lambdas. --- Full diff: https://github.com/llvm/llvm-project/pull/105999.diff 2 Files Affected: - (modified) clang/lib/AST/MicrosoftMangle.cpp (+3-4) - (modified) clang/test/CodeGenCXX/mangle-ms-auto-return.cpp (+14) ``diff diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index b539681984ef7c..018ab617a0ecee 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -2967,13 +2967,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, mangleType(ResultType, Range, QMM_Result); } else if (IsInLambda) { if (const auto *AT = ResultType->getContainedAutoType()) { -assert(AT->getKeyword() == AutoTypeKeyword::Auto && - "should only need to mangle auto!"); -(void)AT; +assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType && + "shouldn't need to mangle __auto_type!"); Out << '?'; mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false); Out << '?'; -mangleSourceName(""); +mangleSourceName(AT->isDecltypeAuto() ? "" : ""); Out << '@'; } else { Out << '@'; diff --git a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp index 5b18dcc0820ee6..0cf59ac962a764 100644 --- a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp +++ b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp @@ -215,6 +215,8 @@ void test_template_decltypeauto() { // Still want to use clang's custom mangling for lambdas to keep backwards compatibility until // MSVC lambda name mangling has been deciphered. void test_lambda() { + int i = 0; + auto lambdaIntRetAuto = []() { return 0; }; lambdaIntRetAuto(); // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" @@ -226,6 +228,18 @@ void test_lambda() { auto lambdaGenericIntIntRetAuto = [](auto a) { return a; }; lambdaGenericIntIntRetAuto(0); // CHECK: call {{.*}} @"??$?RH@@?0??test_lambda@@YAXXZ@QEBA?A?@@H@Z" + + auto lambdaRetTrailingAuto = []() -> auto { return 0; }; + lambdaRetTrailingAuto(); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" + + auto lambdaRetTrailingDecltypeAuto = []() -> decltype(auto) { return 0; }; + lambdaRetTrailingDecltypeAuto(); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" + + auto lambdaRetTrailingRefCollapse = [](int x) -> auto&& { return x; }; + lambdaRetTrailingRefCollapse(i); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@H@Z" } auto TestTrailingInt() -> int { `` https://github.com/llvm/llvm-project/pull/105999 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [AST] Reapply #102848 Fix placeholder return type name mangling for MSVC 1920+ / VS2019+ (PR #104722)
MaxEW707 wrote: @zmodem I have a fix for https://ci.chromium.org/ui/p/chromium/builders/ci/ToTWin. This was an accidental regression on my part, sorry. The fix is here https://github.com/llvm/llvm-project/pull/105999. https://github.com/llvm/llvm-project/pull/104722 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)
https://github.com/tahonermann updated https://github.com/llvm/llvm-project/pull/105738 >From 79b2ceb45cbc4ffb823f56e4c5eedb62f475c780 Mon Sep 17 00:00:00 2001 From: Tom Honermann Date: Thu, 22 Aug 2024 09:44:56 -0700 Subject: [PATCH] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. Clang has historically mimicked gcc behavior for header file searching in which user search paths are ordered before system search paths, user search paths that duplicate a (later) system search path are ignored, and search paths that duplicate an earlier search path of the same user/system kind are ignored. MSVC behavior differs in that user search paths are ordered before system search paths (like gcc), and search paths that duplicate an earlier search path are ignored regardless of user/system kind (similar to gcc, but without the preference for system search paths over duplicate user search paths). The gcc and MSVC differences are observable for driver invocations that pass, e.g., `-Idir1 -isystem dir2 -isystem dir1`. The gcc behavior will result in `dir2` being searched before `dir1` while the MSVC behavior will result in `dir1` being searched before `dir2`. This patch modifies Clang to match the MSVC behavior for handling of duplicate header search paths when running in Microsoft compatibility mode (e.g., when invoked with the `-fms-compatibility` option explicitly or implicitly enabled). --- clang/docs/ReleaseNotes.rst | 14 +++ clang/lib/Lex/InitHeaderSearch.cpp| 21 ++-- clang/test/Driver/header-search-duplicates.c | 76 +++ .../microsoft-header-search-duplicates.c | 97 +++ 4 files changed, 199 insertions(+), 9 deletions(-) create mode 100644 clang/test/Driver/header-search-duplicates.c create mode 100644 clang/test/Driver/microsoft-header-search-duplicates.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 5c156a9c073a9c..d9c96d8902efa9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -363,6 +363,20 @@ Windows Support When `-fms-compatibility-version=18.00` or prior is set on the command line this Microsoft extension is still allowed as VS2013 and prior allow it. +- Clang now matches MSVC behavior for handling of duplicate header search paths + when running in Microsoft compatibility mode. Historically, Clang has + mimicked gcc behavior in which user search paths are ordered before + system search paths, user search paths that duplicate a (later) system search + path are ignored, and search paths that duplicate an earlier search path of + the same user/system kind are ignored. The MSVC behavior is that user search + paths are ordered before system search paths (like gcc), and search paths that + duplicate an earlier search path are ignored regardless of user/system kind + (similar to gcc, but without the preference for system search paths over + duplicate user search paths). These differences are observable for driver + invocations that pass, e.g., `-Idir1 -isystem dir2 -isystem dir1`. The gcc + behavior will search `dir2` before `dir1` and the MSVC behavior will search + `dir1` before `dir2`. + LoongArch Support ^ diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp index 2218db15013d92..3f487f3a4c1c05 100644 --- a/clang/lib/Lex/InitHeaderSearch.cpp +++ b/clang/lib/Lex/InitHeaderSearch.cpp @@ -368,7 +368,8 @@ void InitHeaderSearch::AddDefaultIncludePaths( /// If there are duplicate directory entries in the specified search list, /// remove the later (dead) ones. Returns the number of non-system headers /// removed, which is used to update NumAngled. -static unsigned RemoveDuplicates(std::vector &SearchList, +static unsigned RemoveDuplicates(const LangOptions &Lang, + std::vector &SearchList, unsigned First, bool Verbose) { llvm::SmallPtrSet SeenDirs; llvm::SmallPtrSet SeenFrameworkDirs; @@ -394,14 +395,15 @@ static unsigned RemoveDuplicates(std::vector &SearchList, continue; } -// If we have a normal #include dir/framework/headermap that is shadowed -// later in the chain by a system include location, we actually want to -// ignore the user's request and drop the user dir... keeping the system -// dir. This is weird, but required to emulate GCC's search path correctly. +// When not in MSVC compatibility mode, if we have a normal +// #include dir/framework/headermap that is shadowed later in the chain by +// a system include location, we actually want to ignore the user's request +// and drop the user dir... keeping the system dir. This is weird, but +// required to emulate GCC's search path correctly. // // Since dupes of system dirs are rare, just rescan to find the original // that we're nuking instead of using a DenseM
[clang] [Clang] Start moving X86Builtins.def to X86Builtins.td (PR #106005)
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/106005 This starts moving `X86Builtins.def` to be a tablegen file. It's quite large, so I think it'd be good to move things in multiple steps to avoid a bunch of merge conflicts due to the amount of time this takes to complete. >From b3d0ce2360e83f9499344617ff68a167cc9b2969 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Sun, 25 Aug 2024 21:53:41 +0200 Subject: [PATCH] [Clang] Start moving X86Builtins.def to X86Builtins.td --- clang/include/clang/Basic/BuiltinsBase.td | 4 + clang/include/clang/Basic/BuiltinsX86.def | 126 clang/include/clang/Basic/BuiltinsX86.td | 137 ++ clang/include/clang/Basic/CMakeLists.txt | 4 + clang/include/clang/Basic/TargetBuiltins.h| 2 + clang/lib/Basic/Targets/X86.cpp | 8 + clang/utils/TableGen/ClangBuiltinsEmitter.cpp | 8 +- 7 files changed, 160 insertions(+), 129 deletions(-) create mode 100644 clang/include/clang/Basic/BuiltinsX86.td diff --git a/clang/include/clang/Basic/BuiltinsBase.td b/clang/include/clang/Basic/BuiltinsBase.td index 58dee22fc0a450..cff182f3f282cb 100644 --- a/clang/include/clang/Basic/BuiltinsBase.td +++ b/clang/include/clang/Basic/BuiltinsBase.td @@ -60,6 +60,10 @@ def ConstIgnoringExceptions : Attribute<"g">; // This function requires a specific header or an explicit declaration. def RequireDeclaration : Attribute<"h">; +// FIXME: Why is this not simply the min_vector_width attribute? +// Vector has to be at least N bits wide. +class RequiredVectorWidth : IndexedAttribute<"V", N>; + class PrintfFormat : IndexedAttribute<"p", I>; class VPrintfFormat : IndexedAttribute<"P", I>; class ScanfFormat : IndexedAttribute<"s", I>; diff --git a/clang/include/clang/Basic/BuiltinsX86.def b/clang/include/clang/Basic/BuiltinsX86.def index a696cf117908e2..f578c69d7d4197 100644 --- a/clang/include/clang/Basic/BuiltinsX86.def +++ b/clang/include/clang/Basic/BuiltinsX86.def @@ -26,17 +26,6 @@ # define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif -// Undefined Values -// -TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "") -TARGET_BUILTIN(__builtin_ia32_undef256, "V4d", "ncV:256:", "") -TARGET_BUILTIN(__builtin_ia32_undef512, "V8d", "ncV:512:", "") - -// FLAGS -// -TARGET_BUILTIN(__builtin_ia32_readeflags_u32, "Ui", "n", "") -TARGET_BUILTIN(__builtin_ia32_writeeflags_u32, "vUi", "n", "") - // MMX // // All MMX instructions will be generated via builtins. Any MMX vector @@ -46,113 +35,8 @@ TARGET_BUILTIN(__builtin_ia32_writeeflags_u32, "vUi", "n", "") // argument and our prior approach of using a #define to the current built-in // doesn't work in the presence of re-declaration of _mm_prefetch for windows. TARGET_BUILTIN(_mm_prefetch, "vcC*i", "nc", "mmx") -TARGET_BUILTIN(__builtin_ia32_emms, "v", "n", "mmx") -TARGET_BUILTIN(__builtin_ia32_vec_ext_v4hi, "sV4sIi", "ncV:64:", "sse") -TARGET_BUILTIN(__builtin_ia32_vec_set_v4hi, "V4sV4ssIi", "ncV:64:", "sse") // SSE intrinsics. -TARGET_BUILTIN(__builtin_ia32_comieq, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comilt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comile, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comigt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comige, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comineq, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomieq, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomilt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomile, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomigt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomige, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomineq, "iV4fV4f", "ncV:128:", "sse") - -TARGET_BUILTIN(__builtin_ia32_comisdeq, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdlt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdle, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdgt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdge, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdneq, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdeq, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdlt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdle, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdgt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdge, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdneq, "iV2dV2d", "ncV:128:", "sse2") - -TARGET_BUILTIN(__builtin_ia32_cmpeqps, "V4fV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_cmpltps, "V4fV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__b
[clang] [Clang] Start moving X86Builtins.def to X86Builtins.td (PR #106005)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: Nikolas Klauser (philnik777) Changes This starts moving `X86Builtins.def` to be a tablegen file. It's quite large, so I think it'd be good to move things in multiple steps to avoid a bunch of merge conflicts due to the amount of time this takes to complete. --- Patch is 20.47 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/106005.diff 7 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsBase.td (+4) - (modified) clang/include/clang/Basic/BuiltinsX86.def (-126) - (added) clang/include/clang/Basic/BuiltinsX86.td (+137) - (modified) clang/include/clang/Basic/CMakeLists.txt (+4) - (modified) clang/include/clang/Basic/TargetBuiltins.h (+2) - (modified) clang/lib/Basic/Targets/X86.cpp (+8) - (modified) clang/utils/TableGen/ClangBuiltinsEmitter.cpp (+5-3) ``diff diff --git a/clang/include/clang/Basic/BuiltinsBase.td b/clang/include/clang/Basic/BuiltinsBase.td index 58dee22fc0a450..cff182f3f282cb 100644 --- a/clang/include/clang/Basic/BuiltinsBase.td +++ b/clang/include/clang/Basic/BuiltinsBase.td @@ -60,6 +60,10 @@ def ConstIgnoringExceptions : Attribute<"g">; // This function requires a specific header or an explicit declaration. def RequireDeclaration : Attribute<"h">; +// FIXME: Why is this not simply the min_vector_width attribute? +// Vector has to be at least N bits wide. +class RequiredVectorWidth : IndexedAttribute<"V", N>; + class PrintfFormat : IndexedAttribute<"p", I>; class VPrintfFormat : IndexedAttribute<"P", I>; class ScanfFormat : IndexedAttribute<"s", I>; diff --git a/clang/include/clang/Basic/BuiltinsX86.def b/clang/include/clang/Basic/BuiltinsX86.def index a696cf117908e2..f578c69d7d4197 100644 --- a/clang/include/clang/Basic/BuiltinsX86.def +++ b/clang/include/clang/Basic/BuiltinsX86.def @@ -26,17 +26,6 @@ # define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif -// Undefined Values -// -TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "") -TARGET_BUILTIN(__builtin_ia32_undef256, "V4d", "ncV:256:", "") -TARGET_BUILTIN(__builtin_ia32_undef512, "V8d", "ncV:512:", "") - -// FLAGS -// -TARGET_BUILTIN(__builtin_ia32_readeflags_u32, "Ui", "n", "") -TARGET_BUILTIN(__builtin_ia32_writeeflags_u32, "vUi", "n", "") - // MMX // // All MMX instructions will be generated via builtins. Any MMX vector @@ -46,113 +35,8 @@ TARGET_BUILTIN(__builtin_ia32_writeeflags_u32, "vUi", "n", "") // argument and our prior approach of using a #define to the current built-in // doesn't work in the presence of re-declaration of _mm_prefetch for windows. TARGET_BUILTIN(_mm_prefetch, "vcC*i", "nc", "mmx") -TARGET_BUILTIN(__builtin_ia32_emms, "v", "n", "mmx") -TARGET_BUILTIN(__builtin_ia32_vec_ext_v4hi, "sV4sIi", "ncV:64:", "sse") -TARGET_BUILTIN(__builtin_ia32_vec_set_v4hi, "V4sV4ssIi", "ncV:64:", "sse") // SSE intrinsics. -TARGET_BUILTIN(__builtin_ia32_comieq, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comilt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comile, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comigt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comige, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_comineq, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomieq, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomilt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomile, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomigt, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomige, "iV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_ucomineq, "iV4fV4f", "ncV:128:", "sse") - -TARGET_BUILTIN(__builtin_ia32_comisdeq, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdlt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdle, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdgt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdge, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_comisdneq, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdeq, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdlt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdle, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdgt, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdge, "iV2dV2d", "ncV:128:", "sse2") -TARGET_BUILTIN(__builtin_ia32_ucomisdneq, "iV2dV2d", "ncV:128:", "sse2") - -TARGET_BUILTIN(__builtin_ia32_cmpeqps, "V4fV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_cmpltps, "V4fV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_cmpleps, "V4fV4fV4f", "ncV:128:", "sse") -TARGET_BUILTIN(__builtin_ia32_cmpunordps, "V4fV4fV4f", "ncV:128:",
[clang] [clang][Driver] Define soft float macros for PPC. (PR #106012)
https://github.com/alexrp created https://github.com/llvm/llvm-project/pull/106012 Fixes #105972. From 5d52fe0d6d9bad77193a114eaef324d1799f2444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 25 Aug 2024 22:47:37 +0200 Subject: [PATCH] [clang][Driver] Define soft float macros for PPC. Fixes #105972. --- clang/lib/Basic/Targets/PPC.cpp | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 04dc436eb1b9cd..91145b256804c7 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -402,9 +402,13 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__VEC__", "10206"); Builder.defineMacro("__ALTIVEC__"); } - if (HasSPE) { + if (HasSPE) Builder.defineMacro("__SPE__"); + if (HasSPE || FloatABI == SoftFloat) Builder.defineMacro("__NO_FPRS__"); + if (FloatABI == SoftFloat) { +Builder.defineMacro("_SOFT_FLOAT"); +Builder.defineMacro("_SOFT_DOUBLE"); } if (HasVSX) Builder.defineMacro("__VSX__"); @@ -439,14 +443,12 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, // FIXME: The following are not yet generated here by Clang, but are //generated by GCC: // - // _SOFT_FLOAT_ // __RECIP_PRECISION__ // __APPLE_ALTIVEC__ // __RECIP__ // __RECIPF__ // __RSQRTE__ // __RSQRTEF__ - // _SOFT_DOUBLE_ // __NO_LWSYNC__ // __CMODEL_MEDIUM__ // __CMODEL_LARGE__ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Define soft float macros for PPC. (PR #106012)
llvmbot wrote: @llvm/pr-subscribers-backend-powerpc @llvm/pr-subscribers-clang Author: Alex Rønne Petersen (alexrp) Changes Fixes #105972. --- Full diff: https://github.com/llvm/llvm-project/pull/106012.diff 1 Files Affected: - (modified) clang/lib/Basic/Targets/PPC.cpp (+5-3) ``diff diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 04dc436eb1b9cd..91145b256804c7 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -402,9 +402,13 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__VEC__", "10206"); Builder.defineMacro("__ALTIVEC__"); } - if (HasSPE) { + if (HasSPE) Builder.defineMacro("__SPE__"); + if (HasSPE || FloatABI == SoftFloat) Builder.defineMacro("__NO_FPRS__"); + if (FloatABI == SoftFloat) { +Builder.defineMacro("_SOFT_FLOAT"); +Builder.defineMacro("_SOFT_DOUBLE"); } if (HasVSX) Builder.defineMacro("__VSX__"); @@ -439,14 +443,12 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, // FIXME: The following are not yet generated here by Clang, but are //generated by GCC: // - // _SOFT_FLOAT_ // __RECIP_PRECISION__ // __APPLE_ALTIVEC__ // __RECIP__ // __RECIPF__ // __RSQRTE__ // __RSQRTEF__ - // _SOFT_DOUBLE_ // __NO_LWSYNC__ // __CMODEL_MEDIUM__ // __CMODEL_LARGE__ `` https://github.com/llvm/llvm-project/pull/106012 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Define soft float macros for PPC. (PR #106012)
alexrp wrote: FWIW, if this patch is good, it would be nice to get it into 19.x. https://github.com/llvm/llvm-project/pull/106012 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/101469 >From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Thu, 1 Aug 2024 12:30:22 +0200 Subject: [PATCH 1/6] [Clang] Add [[clang::diagnose_specializations]] --- clang/include/clang/Basic/Attr.td | 13 ++- clang/include/clang/Basic/AttrDocs.td | 14 ++-- clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../clang/Basic/DiagnosticSemaKinds.td| 3 ++ clang/lib/Sema/SemaDeclAttr.cpp | 9 + clang/lib/Sema/SemaTemplate.cpp | 6 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++ 7 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 8ac2079099c854..e074cc8b285a95 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}], "variables with non-local storage">; +def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}], +"variable template">; + def NonBitField : SubsetSubjectisBitField()}], "non-bit-field non-static data members">; @@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr { let Documentation = [DiagnoseIfDocs]; } +def DiagnoseSpecializations : InheritableAttr { + let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>]; + let Subjects = SubjectList<[ClassTmpl, VarTmpl]>; + let Documentation = [DiagnoseSpecializationsDocs]; + let MeaningfulToClassTemplateDefinition = 1; + let TemplateDependent = 1; +} + def ArcWeakrefUnavailable : InheritableAttr { let Spellings = [Clang<"objc_arc_weak_reference_unavailable">]; let Subjects = SubjectList<[ObjCInterface], ErrorDiag>; @@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr { let Spellings = []; let Subjects = SubjectList<[Struct]>; let LangOpts = [HLSL]; - let Args = [ + let Args = [ EnumArgument< "ResourceKind", "llvm::hlsl::ResourceKind", /*is_string=*/0, diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 94c284fc731589..4ca67a63714d4b 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -975,6 +975,15 @@ Query for this feature with ``__has_attribute(diagnose_if)``. }]; } +def DiagnoseSpecializationsDocs : Documentation { + let Category = DocCatDecl; + let Content = [{ +``clang::diagnose_specializations`` can be appied to class templates which +should not be specialized by users. This is primarily used to diagnose user +specializations of standard library type traits. + }]; +} + def PassObjectSizeDocs : Documentation { let Category = DocCatVariable; // Technically it's a parameter doc, but eh. let Heading = "pass_object_size, pass_dynamic_object_size"; @@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation { let Content = [{ The ``[loop]`` directive allows loop optimization hints to be specified for the subsequent loop. The directive allows unrolling to -be disabled and is not compatible with [unroll(x)]. +be disabled and is not compatible with [unroll(x)]. Specifying the parameter, ``[loop]``, directs the -unroller to not unroll the loop. +unroller to not unroll the loop. .. code-block:: hlsl @@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap memory, and prevents any pot of ``nonallocating`` by the compiler. }]; } - diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 19c3f1e0433496..d6f6111f708684 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">; def FlagEnum : DiagGroup<"flag-enum">; def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>; def InfiniteRecursion : DiagGroup<"infinite-recursion">; +def InvalidSpecialization : DiagGroup<"invalid-specialization">; def PureVirtualCallFromCtorDtor: DiagGroup<"call-to-pure-virtual-from-ctor-dtor">; def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">; def IgnoredGCH : DiagGroup<"ignored-gch">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 581434d33c5c9a..5972d630347ec4 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5407,6 +5407,9 @@ def note_dependent_function_template_spec_discard_reason : Note< "candidate ignored: %select{not a function template|" "not a member of the enclosing %select{class template|" "namespace; did y
[clang] [clang-format] Fix misalignments of pointers in angle brackets (PR #106013)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/106013 Fixes #105898. >From a880299cd884d064e2bd03af308afa52736fa75d Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sun, 25 Aug 2024 14:30:32 -0700 Subject: [PATCH] [clang-format] Fix misalignments of pointers in angle brackets Fixes #105898. --- clang/lib/Format/WhitespaceManager.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 9 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index a31874a7c3195a..fa9585ab02eba2 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -469,7 +469,8 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, // except if the token is equal, then a space is needed. if ((Style.PointerAlignment == FormatStyle::PAS_Right || Style.ReferenceAlignment == FormatStyle::RAS_Right) && -CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) { +CurrentChange.Spaces != 0 && +!CurrentChange.Tok->isOneOf(tok::equal, TT_TemplateCloser)) { const bool ReferenceNotRightAligned = Style.ReferenceAlignment != FormatStyle::RAS_Right && Style.ReferenceAlignment != FormatStyle::RAS_Pointer; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a383a624434b1f..e9a7e9654d3063 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -19314,6 +19314,15 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { "X= func(long,\n" "arrg);", Alignment); + + Alignment.ColumnLimit = 80; + Alignment.SpacesInAngles = FormatStyle::SIAS_Always; + verifyFormat("void **ptr = reinterpret_cast< void ** >(unkn);\n" + "ptr= reinterpret_cast< void ** >(ptr[0]);", + Alignment); + verifyFormat("quint32 *dstimg = reinterpret_cast< quint32 * >(out(i));\n" + "quint32 *dstmask = reinterpret_cast< quint32 * >(outmask(i));", + Alignment); } TEST_F(FormatTest, AlignConsecutiveBitFields) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix misalignments of pointers in angle brackets (PR #106013)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #105898. --- Full diff: https://github.com/llvm/llvm-project/pull/106013.diff 2 Files Affected: - (modified) clang/lib/Format/WhitespaceManager.cpp (+2-1) - (modified) clang/unittests/Format/FormatTest.cpp (+9) ``diff diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index a31874a7c3195a..fa9585ab02eba2 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -469,7 +469,8 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, // except if the token is equal, then a space is needed. if ((Style.PointerAlignment == FormatStyle::PAS_Right || Style.ReferenceAlignment == FormatStyle::RAS_Right) && -CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) { +CurrentChange.Spaces != 0 && +!CurrentChange.Tok->isOneOf(tok::equal, TT_TemplateCloser)) { const bool ReferenceNotRightAligned = Style.ReferenceAlignment != FormatStyle::RAS_Right && Style.ReferenceAlignment != FormatStyle::RAS_Pointer; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a383a624434b1f..e9a7e9654d3063 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -19314,6 +19314,15 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { "X= func(long,\n" "arrg);", Alignment); + + Alignment.ColumnLimit = 80; + Alignment.SpacesInAngles = FormatStyle::SIAS_Always; + verifyFormat("void **ptr = reinterpret_cast< void ** >(unkn);\n" + "ptr= reinterpret_cast< void ** >(ptr[0]);", + Alignment); + verifyFormat("quint32 *dstimg = reinterpret_cast< quint32 * >(out(i));\n" + "quint32 *dstmask = reinterpret_cast< quint32 * >(outmask(i));", + Alignment); } TEST_F(FormatTest, AlignConsecutiveBitFields) { `` https://github.com/llvm/llvm-project/pull/106013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] `__noop` not marked as constexpr #102064 (PR #105983)
ofAlpaca wrote: @DanielJump Could you kindly help me review my commit? Besides, I'm not sure how to solve the failed build test on GitHub. The failed case is `C:\ws\src\clang\unittests\Support\TimeProfilerTest.cpp:278` on Windows platform. It shows the following difference. ``` With diff: @@ -7,5 +7,5 @@ | | ParseFunctionDefinition (user) | PerformPendingInstantiations -| | InstantiateFunction (fooA, ./a.h:7) -| | | InstantiateFunction (fooB, ./b.h:3) -| | | InstantiateFunction (fooMTA, ./a.h:4)\n +| | InstantiateFunction (fooA, .\\a.h:7) +| | | InstantiateFunction (fooB, .\\b.h:3) +| | | InstantiateFunction (fooMTA, .\\a.h:4)\n ``` It looks like the problem is about Windows's backslash. However, I don't know how this error relates to my code. https://github.com/llvm/llvm-project/pull/105983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (PR #105999)
https://github.com/petrhosek approved this pull request. https://github.com/llvm/llvm-project/pull/105999 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)
https://github.com/tahonermann ready_for_review https://github.com/llvm/llvm-project/pull/105738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)
tahonermann wrote: It took me a few tries to get the tests tweaked just right for the `clang-cl` driver to pass on Windows, but the tests now pass and this PR is now ready for review. https://github.com/llvm/llvm-project/pull/105738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] Rewrote test to work with lit internal shell syntax (PR #105902)
https://github.com/ChuanqiXu9 approved this pull request. LGTM on my side. Thanks. But I didn't take a detailed look into https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179/29. So it might be good to wait for people there to approve this https://github.com/llvm/llvm-project/pull/105902 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Warn for duplicated decls in mutliple module units (PR #105799)
@@ -9955,6 +9955,45 @@ void ASTReader::finishPendingActions() { } PendingDefinitions.clear(); + for (auto [D, Previous] : PendingWarningForDuplicatedDefsInModuleUnits) { +auto hasDefinitionImpl = [this](Decl *D, auto hasDefinitionImpl) { + if (auto *VD = dyn_cast(D)) +return VD->isThisDeclarationADefinition() || + VD->isThisDeclarationADemotedDefinition(); + + if (auto *TD = dyn_cast(D)) +return TD->isThisDeclarationADefinition() || + TD->isThisDeclarationADemotedDefinition(); + + if (auto *FD = dyn_cast(D)) +return FD->isThisDeclarationADefinition() || PendingBodies.count(FD); + + if (auto *RTD = dyn_cast(D)) +return hasDefinitionImpl(RTD->getTemplatedDecl(), hasDefinitionImpl); + + // Conservatively return false here. + return false; +}; + +auto hasDefinition = [this, &hasDefinitionImpl](Decl *D) { ChuanqiXu9 wrote: Thanks and this looks to be fixed by someoneelse. Thanks again! https://github.com/llvm/llvm-project/pull/105799 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy] Add support for bsl::optional (PR #101450)
https://github.com/dayshah approved this pull request. huge for bloomberg 🔥 https://github.com/llvm/llvm-project/pull/101450 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Update TODO comment check (PR #104868)
@@ -24,3 +24,7 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow missing semicolon +// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. +// TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. +// TODO(bug 12345678): Update this list after the Foo service is turned down. +// TODO(John): Use a "\*" here for concatenation operator. AlanRosenthal wrote: Great point, done. https://github.com/llvm/llvm-project/pull/104868 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Update TODO comment check (PR #104868)
https://github.com/AlanRosenthal updated https://github.com/llvm/llvm-project/pull/104868 >From 5f84cc47cde13732ed61eccc0b17f6c420a64ab7 Mon Sep 17 00:00:00 2001 From: Alan Rosenthal Date: Thu, 22 Aug 2024 21:42:04 + Subject: [PATCH 1/2] [clang-tidy] Update TODO comment check The doc for google-readability-todo reference: https://google.github.io/styleguide/cppguide.html#TODO_Comments Which lists two styles of TODO comments. Previously, only `TODO(John): comment` were supported. After this PR, `TODO: bug 123 - comment` are also supported. --- .../clang-tidy/google/TodoCommentCheck.cpp| 21 +-- .../checkers/google/readability-todo.cpp | 4 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp index adad54aa24ba99..9c7b10214bcdc8 100644 --- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp @@ -9,6 +9,7 @@ #include "TodoCommentCheck.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" +#include #include namespace clang::tidy::google::readability { @@ -17,21 +18,29 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { public: TodoCommentHandler(TodoCommentCheck &Check, std::optional User) : Check(Check), User(User ? *User : "unknown"), -TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {} +TodoMatches{llvm::Regex("^// TODO: (.*) - (.*)$"), +llvm::Regex("^// *TODO *(\\(.*\\))?:? ?(.*)$")} {} bool HandleComment(Preprocessor &PP, SourceRange Range) override { StringRef Text = Lexer::getSourceText(CharSourceRange::getCharRange(Range), PP.getSourceManager(), PP.getLangOpts()); +bool Found = false; SmallVector Matches; -if (!TodoMatch.match(Text, &Matches)) +for (const llvm::Regex &TodoMatch : TodoMatches) { + if (TodoMatch.match(Text, &Matches)) { +Found = true; +break; + } +} +if (!Found) return false; -StringRef Username = Matches[1]; -StringRef Comment = Matches[3]; +StringRef Info = Matches[1]; +StringRef Comment = Matches[2]; -if (!Username.empty()) +if (!Info.empty()) return false; std::string NewText = ("// TODO(" + Twine(User) + "): " + Comment).str(); @@ -45,7 +54,7 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { private: TodoCommentCheck &Check; std::string User; - llvm::Regex TodoMatch; + std::array TodoMatches; }; TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context) diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp index 6b900aa92150e8..e41f84b31dabb8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp @@ -24,3 +24,7 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow missing semicolon +// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. +// TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. +// TODO(bug 12345678): Update this list after the Foo service is turned down. +// TODO(John): Use a "\*" here for concatenation operator. >From a9a524d2627c2f0a43e4f8a05d06184842233088 Mon Sep 17 00:00:00 2001 From: Alan Rosenthal <1288897+alanrosent...@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:13:23 -0400 Subject: [PATCH 2/2] PR feedback --- clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp| 2 +- .../test/clang-tidy/checkers/google/readability-todo.cpp| 6 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp index 9c7b10214bcdc8..cd0457a6ae5132 100644 --- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp @@ -9,7 +9,7 @@ #include "TodoCommentCheck.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" -#include +#include #include namespace clang::tidy::google::readability { diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp index e41f84b31dabb8..daab83091e3174 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp @@ -24,7 +24,5 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow mis
[clang-tools-extra] [clang-tidy] Update TODO comment check (PR #104868)
https://github.com/AlanRosenthal updated https://github.com/llvm/llvm-project/pull/104868 >From 5f84cc47cde13732ed61eccc0b17f6c420a64ab7 Mon Sep 17 00:00:00 2001 From: Alan Rosenthal Date: Thu, 22 Aug 2024 21:42:04 + Subject: [PATCH 1/3] [clang-tidy] Update TODO comment check The doc for google-readability-todo reference: https://google.github.io/styleguide/cppguide.html#TODO_Comments Which lists two styles of TODO comments. Previously, only `TODO(John): comment` were supported. After this PR, `TODO: bug 123 - comment` are also supported. --- .../clang-tidy/google/TodoCommentCheck.cpp| 21 +-- .../checkers/google/readability-todo.cpp | 4 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp index adad54aa24ba99..9c7b10214bcdc8 100644 --- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp @@ -9,6 +9,7 @@ #include "TodoCommentCheck.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" +#include #include namespace clang::tidy::google::readability { @@ -17,21 +18,29 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { public: TodoCommentHandler(TodoCommentCheck &Check, std::optional User) : Check(Check), User(User ? *User : "unknown"), -TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {} +TodoMatches{llvm::Regex("^// TODO: (.*) - (.*)$"), +llvm::Regex("^// *TODO *(\\(.*\\))?:? ?(.*)$")} {} bool HandleComment(Preprocessor &PP, SourceRange Range) override { StringRef Text = Lexer::getSourceText(CharSourceRange::getCharRange(Range), PP.getSourceManager(), PP.getLangOpts()); +bool Found = false; SmallVector Matches; -if (!TodoMatch.match(Text, &Matches)) +for (const llvm::Regex &TodoMatch : TodoMatches) { + if (TodoMatch.match(Text, &Matches)) { +Found = true; +break; + } +} +if (!Found) return false; -StringRef Username = Matches[1]; -StringRef Comment = Matches[3]; +StringRef Info = Matches[1]; +StringRef Comment = Matches[2]; -if (!Username.empty()) +if (!Info.empty()) return false; std::string NewText = ("// TODO(" + Twine(User) + "): " + Comment).str(); @@ -45,7 +54,7 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { private: TodoCommentCheck &Check; std::string User; - llvm::Regex TodoMatch; + std::array TodoMatches; }; TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context) diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp index 6b900aa92150e8..e41f84b31dabb8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp @@ -24,3 +24,7 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow missing semicolon +// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. +// TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. +// TODO(bug 12345678): Update this list after the Foo service is turned down. +// TODO(John): Use a "\*" here for concatenation operator. >From a9a524d2627c2f0a43e4f8a05d06184842233088 Mon Sep 17 00:00:00 2001 From: Alan Rosenthal <1288897+alanrosent...@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:13:23 -0400 Subject: [PATCH 2/3] PR feedback --- clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp| 2 +- .../test/clang-tidy/checkers/google/readability-todo.cpp| 6 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp index 9c7b10214bcdc8..cd0457a6ae5132 100644 --- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp @@ -9,7 +9,7 @@ #include "TodoCommentCheck.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" -#include +#include #include namespace clang::tidy::google::readability { diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp index e41f84b31dabb8..daab83091e3174 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp @@ -24,7 +24,5 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow mis
[clang] 88f9ac3 - [doc] [C++20] [Modules] Add docs and release notes for '-Wdecls-in-multiple-modules'
Author: Chuanqi Xu Date: 2024-08-26T10:52:05+08:00 New Revision: 88f9ac380d8b40742aea11c8278652711261abff URL: https://github.com/llvm/llvm-project/commit/88f9ac380d8b40742aea11c8278652711261abff DIFF: https://github.com/llvm/llvm-project/commit/88f9ac380d8b40742aea11c8278652711261abff.diff LOG: [doc] [C++20] [Modules] Add docs and release notes for '-Wdecls-in-multiple-modules' As the title shows. Added: Modified: clang/docs/ReleaseNotes.rst clang/docs/StandardCPlusPlusModules.rst Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6e1db41a55cbe0..2c6c7e083b9c91 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -249,6 +249,11 @@ Improvements to Clang's diagnostics a warning which defaults to being an error, is enabled by default, and is also controlled by the now-deprecated ``-fheinous-gnu-extensions`` flag. +- Added the ``-Wdecls-in-multiple-modules`` option to assist users to identify + multiple declarations in diff erent modules, which is the major reason of the slow + compilation speed with modules. This warning is disabled by default and it needs + to be explicitly enabled or by ``-Weverything``. + Improvements to Clang's time-trace -- diff --git a/clang/docs/StandardCPlusPlusModules.rst b/clang/docs/StandardCPlusPlusModules.rst index 1469feb3ad45bd..2b757a807a0e6e 100644 --- a/clang/docs/StandardCPlusPlusModules.rst +++ b/clang/docs/StandardCPlusPlusModules.rst @@ -894,6 +894,9 @@ approach: Reducing the duplication from textual includes is what improves compile-time performance. +To help users to identify such issues, we add a warning ``-Wdecls-in-multiple-modules``. +This warning is disabled by default and it needs to be explicitly enabled or by ``-Weverything``. + Transitioning to modules ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] fix crash in include cleaner (PR #99514)
https://github.com/HighCommander4 requested changes to this pull request. Having debugged the failing scenario a bit (see [this comment](https://github.com/llvm/llvm-project/issues/99617#issuecomment-2309220224)), my sense is that we do not want to accept `MacroRefs` entries which are not in the main file; instead, I have a proposal for an alternative solution at the end of that comment. Let me know if you're interested in implementing it, otherwise I can do it. https://github.com/llvm/llvm-project/pull/99514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2579b41 - [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (#105999)
Author: Max Winkler Date: 2024-08-25T20:48:07-07:00 New Revision: 2579b411a13799534c8b8a22246134b88ba7785d URL: https://github.com/llvm/llvm-project/commit/2579b411a13799534c8b8a22246134b88ba7785d DIFF: https://github.com/llvm/llvm-project/commit/2579b411a13799534c8b8a22246134b88ba7785d.diff LOG: [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (#105999) Fixes https://github.com/llvm/llvm-project/pull/104722. Missed handling `decltype(auto)` trailing return types for lambdas. This was a mistake and regression on my part with my PR, https://github.com/llvm/llvm-project/pull/104722. Added some missing unit tests to test for the various placeholder trailing return types in lambdas. Added: Modified: clang/lib/AST/MicrosoftMangle.cpp clang/test/CodeGenCXX/mangle-ms-auto-return.cpp Removed: diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index b539681984ef7c..018ab617a0ecee 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -2967,13 +2967,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, mangleType(ResultType, Range, QMM_Result); } else if (IsInLambda) { if (const auto *AT = ResultType->getContainedAutoType()) { -assert(AT->getKeyword() == AutoTypeKeyword::Auto && - "should only need to mangle auto!"); -(void)AT; +assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType && + "shouldn't need to mangle __auto_type!"); Out << '?'; mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false); Out << '?'; -mangleSourceName(""); +mangleSourceName(AT->isDecltypeAuto() ? "" : ""); Out << '@'; } else { Out << '@'; diff --git a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp index 5b18dcc0820ee6..0cf59ac962a764 100644 --- a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp +++ b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp @@ -215,6 +215,8 @@ void test_template_decltypeauto() { // Still want to use clang's custom mangling for lambdas to keep backwards compatibility until // MSVC lambda name mangling has been deciphered. void test_lambda() { + int i = 0; + auto lambdaIntRetAuto = []() { return 0; }; lambdaIntRetAuto(); // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" @@ -226,6 +228,18 @@ void test_lambda() { auto lambdaGenericIntIntRetAuto = [](auto a) { return a; }; lambdaGenericIntIntRetAuto(0); // CHECK: call {{.*}} @"??$?RH@@?0??test_lambda@@YAXXZ@QEBA?A?@@H@Z" + + auto lambdaRetTrailingAuto = []() -> auto { return 0; }; + lambdaRetTrailingAuto(); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" + + auto lambdaRetTrailingDecltypeAuto = []() -> decltype(auto) { return 0; }; + lambdaRetTrailingDecltypeAuto(); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@XZ" + + auto lambdaRetTrailingRefCollapse = [](int x) -> auto&& { return x; }; + lambdaRetTrailingRefCollapse(i); + // CHECK: call {{.*}} @"??R@?0??test_lambda@@YAXXZ@QEBA?A?@@H@Z" } auto TestTrailingInt() -> int { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (PR #105999)
https://github.com/MaxEW707 closed https://github.com/llvm/llvm-project/pull/105999 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AArch64] Add SME2.1 feature macros (PR #105657)
aemerson wrote: These need to be back ported onto the release branch ASAP. https://github.com/llvm/llvm-project/pull/105657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] poor diagnostic due to overloading in extern "C" block (PR #106033)
https://github.com/s-watanabe314 created https://github.com/llvm/llvm-project/pull/106033 Fixes #80235 When trying to overload a function within `extern "C"`, the diagnostic `functions that differ only in their return type cannot be overloaded` is given. This diagnostic is inappropriate because overloading is basically not allowed in the C language. However, if the redeclared function has the `((overloadable))` attribute, it should be diagnosed as `functions that differ only in their return type cannot be overloaded`. This patch uses `isExternC()` to provide an appropriate diagnostic during the diagnostic process. `isExternC()` updates the linkage information cache internally, so calling it before merging functions can cause clang to crash. An example is declaring `static void foo()` and `void foo()` within an `extern "C"` block. Therefore, I decided to call `isExternC()` after the compilation error is confirmed and select the diagnostic message. The diagnostic message is `conflicting types for 'func'` similar to the diagnostic in C, and `functions that differ only in their return type cannot be overloaded` if the `((overloadable))` attribute is given. Regression tests verify that the expected diagnostics are given when trying to overload functions within `extern "C"` and when the `((overloadable))` attribute is present. >From 74424f222488d6a73d5d903bca470886414f37d9 Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Fri, 23 Aug 2024 17:37:57 +0900 Subject: [PATCH] poor diagnostic due to overloading in extern "C" block #80235 Fixes #80235 When trying to overload a function within `extern "C"`, the diagnostic `functions that differ only in their return type cannot be overloaded` is given. This diagnostic is inappropriate because overloading is basically not allowed in the C language. However, if the redeclared function has the `((overloadable))` attribute, it should be diagnosed as `functions that differ only in their return type cannot be overloaded`. This patch uses `isExternC()` to provide an appropriate diagnostic during the diagnostic process. `isExternC()` updates the linkage information cache internally, so calling it before merging functions can cause clang to crash. An example is declaring `static void foo()` and `void foo()` within an `extern "C"` block. Therefore, I decided to call `isExternC()` after the compilation error is confirmed and select the diagnostic message. The diagnostic message is `conflicting types for 'func'` similar to the diagnostic in C, and `functions that differ only in their return type cannot be overloaded` if the `((overloadable))` attribute is given. Regression tests verify that the expected diagnostics are given when trying to overload functions within `extern "C"` and when the `((overloadable))` attribute is present. --- clang/lib/Sema/SemaDecl.cpp | 4 clang/test/SemaCXX/extern-c.cpp | 19 +++ 2 files changed, 23 insertions(+) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 503e93f9257137..63bd15dad7c48a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3882,6 +3882,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S, if (New->isCXXClassMember() && New->isOutOfLine()) Diag(New->getLocation(), diag::err_member_def_does_not_match_ret_type) << New << New->getReturnTypeSourceRange(); +else if (Old->isExternC() && New->isExternC() && + !Old->hasAttr() && + !New->hasAttr()) + Diag(New->getLocation(), diag::err_conflicting_types) << New; else Diag(New->getLocation(), diag::err_ovl_diff_return_type) << New->getReturnTypeSourceRange(); diff --git a/clang/test/SemaCXX/extern-c.cpp b/clang/test/SemaCXX/extern-c.cpp index 68d1494b94918f..86012670ddcd57 100644 --- a/clang/test/SemaCXX/extern-c.cpp +++ b/clang/test/SemaCXX/extern-c.cpp @@ -77,6 +77,19 @@ namespace foo { } } +namespace extern_ovl { + extern "C" { +__attribute__((overloadable)) +void ovl_decl(void); // expected-note {{previous}} + +__attribute__((overloadable)) +int ovl_decl(int); + +__attribute__((overloadable)) +int ovl_decl(void); // expected-error {{functions that differ only in their return type}} + } +} + namespace linkage { namespace redecl { extern "C" { @@ -88,6 +101,12 @@ namespace linkage { void linkage_redecl(double); // expected-error {{conflicting types}} } } + namespace redecl_2 { +extern "C" { + void linkage_redecl_2(); // expected-note {{previous}} + int linkage_redecl_2(int); // expected-error {{conflicting types}} +} + } namespace from_outer { void linkage_from_outer_1(); // expected-note {{previous}} void linkage_from_outer_2(); // expected-note {{previous}} ___ cfe-commits mailing list cfe-commits@li
[clang] poor diagnostic due to overloading in extern "C" block (PR #106033)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/106033 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] poor diagnostic due to overloading in extern "C" block (PR #106033)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (s-watanabe314) Changes Fixes #80235 When trying to overload a function within `extern "C"`, the diagnostic `functions that differ only in their return type cannot be overloaded` is given. This diagnostic is inappropriate because overloading is basically not allowed in the C language. However, if the redeclared function has the `((overloadable))` attribute, it should be diagnosed as `functions that differ only in their return type cannot be overloaded`. This patch uses `isExternC()` to provide an appropriate diagnostic during the diagnostic process. `isExternC()` updates the linkage information cache internally, so calling it before merging functions can cause clang to crash. An example is declaring `static void foo()` and `void foo()` within an `extern "C"` block. Therefore, I decided to call `isExternC()` after the compilation error is confirmed and select the diagnostic message. The diagnostic message is `conflicting types for 'func'` similar to the diagnostic in C, and `functions that differ only in their return type cannot be overloaded` if the `((overloadable))` attribute is given. Regression tests verify that the expected diagnostics are given when trying to overload functions within `extern "C"` and when the `((overloadable))` attribute is present. --- Full diff: https://github.com/llvm/llvm-project/pull/106033.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaDecl.cpp (+4) - (modified) clang/test/SemaCXX/extern-c.cpp (+19) ``diff diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 503e93f9257137..63bd15dad7c48a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3882,6 +3882,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S, if (New->isCXXClassMember() && New->isOutOfLine()) Diag(New->getLocation(), diag::err_member_def_does_not_match_ret_type) << New << New->getReturnTypeSourceRange(); +else if (Old->isExternC() && New->isExternC() && + !Old->hasAttr() && + !New->hasAttr()) + Diag(New->getLocation(), diag::err_conflicting_types) << New; else Diag(New->getLocation(), diag::err_ovl_diff_return_type) << New->getReturnTypeSourceRange(); diff --git a/clang/test/SemaCXX/extern-c.cpp b/clang/test/SemaCXX/extern-c.cpp index 68d1494b94918f..86012670ddcd57 100644 --- a/clang/test/SemaCXX/extern-c.cpp +++ b/clang/test/SemaCXX/extern-c.cpp @@ -77,6 +77,19 @@ namespace foo { } } +namespace extern_ovl { + extern "C" { +__attribute__((overloadable)) +void ovl_decl(void); // expected-note {{previous}} + +__attribute__((overloadable)) +int ovl_decl(int); + +__attribute__((overloadable)) +int ovl_decl(void); // expected-error {{functions that differ only in their return type}} + } +} + namespace linkage { namespace redecl { extern "C" { @@ -88,6 +101,12 @@ namespace linkage { void linkage_redecl(double); // expected-error {{conflicting types}} } } + namespace redecl_2 { +extern "C" { + void linkage_redecl_2(); // expected-note {{previous}} + int linkage_redecl_2(int); // expected-error {{conflicting types}} +} + } namespace from_outer { void linkage_from_outer_1(); // expected-note {{previous}} void linkage_from_outer_2(); // expected-note {{previous}} `` https://github.com/llvm/llvm-project/pull/106033 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (PR #105999)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` running on `sanitizer-buildbot1` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/3102 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... [373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o [374/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o [375/378] Generating Msan-x86_64-with-call-Test [376/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o [377/378] Generating Msan-x86_64-Test [377/378] Running compiler_rt regression tests llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276: warning: input '/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/rtsan/X86_64LinuxConfig' contained no tests llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 10142 tests, 88 workers -- Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. FAIL: SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp (6989 of 10142) TEST 'SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 2: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp + /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp RUN: at line 5: env LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1 /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp 2>&1 | FileCheck /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -check-prefix=CHECK_MAY_RETURN_1 + env LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1 /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp + FileCheck /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -check-prefix=CHECK_MAY_RETURN_1 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp:68:24: error: CHECK_MAY_RETURN_1: expected string not found in input // CHECK_MAY_RETURN_1: allocating 512 times ^ :52:44: note: scanning from here Some of the malloc calls returned non-null: 256 ^ :52:45: note: possible intended match here Some of the malloc calls returned non-null: 256 ^ Input file: Check file: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -dump-input=help explains the following input dump. Input was: << . . . 47: [256] 48: [320] 49: [384] 50: [448] 51: Some of the malloc calls returned null: 256 52: Some of the malloc calls returned non-null: 256 check:68'0X error: no match found check:68'1 ?possible intended match Step 14 (test compiler-rt default) failure: test compiler-rt default (failure) ... [373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o [374/378] Generating MSAN_INST_TEST_OBJECTS
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/106036 Fixes #92196 https://eel.is/c++draft/macro.names#2 > A translation unit shall not #define or #undef names lexically identical to > keywords, to the identifiers listed in Table > [4](https://eel.is/c++draft/lex.name#tab:lex.name.special), or to the > [attribute-token](https://eel.is/c++draft/dcl.attr.grammar#nt:attribute-token)s > described in [[dcl.attr]](https://eel.is/c++draft/dcl.attr), except that the > names likely and unlikely may be defined as function-like macros > ([[cpp.replace]](https://eel.is/c++draft/cpp.replace))[.](https://eel.is/c++draft/macro.names#2.sentence-1) >From 67e70c3abc2527d2f35abdc10ce2710dd9ebb918 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 26 Aug 2024 07:37:04 +0300 Subject: [PATCH] [Clang] restrict use of attribute names reserved by the C++ standard --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Lex/PPDirectives.cpp| 22 + .../Preprocessor/macro-reserved-attrs.cpp | 33 +++ 3 files changed, 57 insertions(+) create mode 100644 clang/test/Preprocessor/macro-reserved-attrs.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2c6c7e083b9c91..b8b76eb0ff380c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -254,6 +254,8 @@ Improvements to Clang's diagnostics compilation speed with modules. This warning is disabled by default and it needs to be explicitly enabled or by ``-Weverything``. +- Clang now diagnoses the use of attribute names reserved by the C++ standard. (#GH92196). + Improvements to Clang's time-trace -- diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 4e77df9ec444c7..bbe1b4a640c4ac 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { + const LangOptions &Lang = PP.getLangOpts(); + const StringRef Name = II->getName(); + + if (Lang.CPlusPlus26) +return Name == "indeterminate"; + if (Lang.CPlusPlus23) +return Name == "assume"; + if (Lang.CPlusPlus20) +return Name == "no_unique_address"; + if (Lang.CPlusPlus17) +return Name == "fallthrough" || Name == "nodiscard" || + Name == "maybe_unused"; + if (Lang.CPlusPlus14) +return Name == "deprecated"; + if (Lang.CPlusPlus11) +return Name == "noreturn" || Name == "carries_dependency"; + return false; +} + static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) { const LangOptions &Lang = PP.getLangOpts(); StringRef Text = II->getName(); @@ -186,6 +206,8 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) { return MD_KeywordDef; if (Lang.CPlusPlus11 && (Text == "override" || Text == "final")) return MD_KeywordDef; + if (isReservedAttrName(PP, II)) +return MD_KeywordDef; return MD_NoWarn; } diff --git a/clang/test/Preprocessor/macro-reserved-attrs.cpp b/clang/test/Preprocessor/macro-reserved-attrs.cpp new file mode 100644 index 00..b4336f801e438a --- /dev/null +++ b/clang/test/Preprocessor/macro-reserved-attrs.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx11 -pedantic -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -pedantic -std=c++14 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 -pedantic -std=c++17 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -pedantic -std=c++20 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -pedantic -std=c++23 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx26 -pedantic -std=c++26 %s + +#define noreturn 1 // cxx11-warning {{keyword is hidden by macro definition}} +#undef noreturn + +#define carries_dependency 1 // cxx11-warning {{keyword is hidden by macro definition}} +#undef carries_dependency + +#define deprecated 1 // cxx14-warning {{keyword is hidden by macro definition}} +#undef deprecated + +#define fallthrough 1// cxx17-warning {{keyword is hidden by macro definition}} +#undef fallthrough + +#define maybe_unused 1 // cxx17-warning {{keyword is hidden by macro definition}} +#undef maybe_unused + +#define nodiscard 1 // cxx17-warning {{keyword is hidden by macro definition}} +#undef nodiscard + +#define no_unique_address 1 // cxx20-warning {{keyword is hidden by macro definition}} +#undef no_unique_address + +#define assume 1 // cxx23-warning {{keyword is hidden by macro definition}} +#undef assume + +#define indeterminate 1 // cxx26-warning {{keyword is hidden by macro definition}} +#undef indeterminate ___ cfe-commits mailing list cfe-
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) Changes Fixes #92196 https://eel.is/c++draft/macro.names#2 > A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table [4](https://eel.is/c++draft/lex.name#tab:lex.name.special), or to the [attribute-token](https://eel.is/c++draft/dcl.attr.grammar#nt:attribute-token)s described in [[dcl.attr]](https://eel.is/c++draft/dcl.attr), except that the names likely and unlikely may be defined as function-like macros ([[cpp.replace]](https://eel.is/c++draft/cpp.replace))[.](https://eel.is/c++draft/macro.names#2.sentence-1) --- Full diff: https://github.com/llvm/llvm-project/pull/106036.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Lex/PPDirectives.cpp (+22) - (added) clang/test/Preprocessor/macro-reserved-attrs.cpp (+33) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2c6c7e083b9c91..b8b76eb0ff380c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -254,6 +254,8 @@ Improvements to Clang's diagnostics compilation speed with modules. This warning is disabled by default and it needs to be explicitly enabled or by ``-Weverything``. +- Clang now diagnoses the use of attribute names reserved by the C++ standard. (#GH92196). + Improvements to Clang's time-trace -- diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 4e77df9ec444c7..bbe1b4a640c4ac 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { + const LangOptions &Lang = PP.getLangOpts(); + const StringRef Name = II->getName(); + + if (Lang.CPlusPlus26) +return Name == "indeterminate"; + if (Lang.CPlusPlus23) +return Name == "assume"; + if (Lang.CPlusPlus20) +return Name == "no_unique_address"; + if (Lang.CPlusPlus17) +return Name == "fallthrough" || Name == "nodiscard" || + Name == "maybe_unused"; + if (Lang.CPlusPlus14) +return Name == "deprecated"; + if (Lang.CPlusPlus11) +return Name == "noreturn" || Name == "carries_dependency"; + return false; +} + static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) { const LangOptions &Lang = PP.getLangOpts(); StringRef Text = II->getName(); @@ -186,6 +206,8 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) { return MD_KeywordDef; if (Lang.CPlusPlus11 && (Text == "override" || Text == "final")) return MD_KeywordDef; + if (isReservedAttrName(PP, II)) +return MD_KeywordDef; return MD_NoWarn; } diff --git a/clang/test/Preprocessor/macro-reserved-attrs.cpp b/clang/test/Preprocessor/macro-reserved-attrs.cpp new file mode 100644 index 00..b4336f801e438a --- /dev/null +++ b/clang/test/Preprocessor/macro-reserved-attrs.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx11 -pedantic -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -pedantic -std=c++14 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 -pedantic -std=c++17 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -pedantic -std=c++20 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -pedantic -std=c++23 %s +// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx26 -pedantic -std=c++26 %s + +#define noreturn 1 // cxx11-warning {{keyword is hidden by macro definition}} +#undef noreturn + +#define carries_dependency 1 // cxx11-warning {{keyword is hidden by macro definition}} +#undef carries_dependency + +#define deprecated 1 // cxx14-warning {{keyword is hidden by macro definition}} +#undef deprecated + +#define fallthrough 1// cxx17-warning {{keyword is hidden by macro definition}} +#undef fallthrough + +#define maybe_unused 1 // cxx17-warning {{keyword is hidden by macro definition}} +#undef maybe_unused + +#define nodiscard 1 // cxx17-warning {{keyword is hidden by macro definition}} +#undef nodiscard + +#define no_unique_address 1 // cxx20-warning {{keyword is hidden by macro definition}} +#undef no_unique_address + +#define assume 1 // cxx23-warning {{keyword is hidden by macro definition}} +#undef assume + +#define indeterminate 1 // cxx26-warning {{keyword is hidden by macro definition}} +#undef indeterminate `` https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revisit the fix for the lambda within a type alias template decl (PR #89934)
cor3ntin wrote: I think this is reasonable. We are missing a changelog entry though https://github.com/llvm/llvm-project/pull/89934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revisit the fix for the lambda within a type alias template decl (PR #89934)
@@ -91,15 +91,60 @@ void bar() { namespace GH82104 { -template int Zero = 0; +template int Value = sizeof...(D); -template -using T14 = decltype([]() { return Zero; }()); +template +using T14 = decltype([](auto Param) { + return Value + V + (int)sizeof(Param); +}("hello")); template using T15 = T14; static_assert(__is_same(T15, int)); +// FIXME: This still crashes because we can't extract template arguments T and U +// outside of the instantiation context of T16. +#if 0 +template +using T16 = decltype([](auto Param) requires (sizeof(Param) != 1 && sizeof...(U) > 0) { + return Value + sizeof(Param); +}); +static_assert(T16()(42) == 2 + sizeof(42)); +#endif cor3ntin wrote: Maybe, or something along those lines. (Or maybe we need to push some sort of state when parsing / transforming an alias and have a more generic way to get at template parameter) https://github.com/llvm/llvm-project/pull/89934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)
@@ -10705,7 +10705,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/1815.html";>1815 CD4 Lifetime extension in aggregate initialization -No +Clang 19 cor3ntin wrote: ```suggestion Clang 20 ``` https://github.com/llvm/llvm-project/pull/97308 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)
@@ -5567,19 +5568,35 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) { ImmediateCallVisitor V(getASTContext()); if (!NestedDefaultChecking) V.TraverseDecl(Field); - if (V.HasImmediateCalls) { + + // CWG1815 + // Support lifetime extension of temporary created by aggregate + // initialization using a default member initializer. We should always rebuild + // the initializer if it contains any temporaries (if the initializer + // expression is an ExprWithCleanups). Then make sure the normal lifetime + // extension code recurses into the default initializer and does lifetime + // extension when warranted. + bool ContainsAnyTemporaries = + isa_and_present(Field->getInClassInitializer()); + if (V.HasImmediateCalls || InLifetimeExtendingContext || + ContainsAnyTemporaries) { ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field, CurContext}; ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer = NestedDefaultChecking; - +// Pass down lifetime extending flag, and collect temporaries in +// CreateMaterializeTemporaryExpr when we rewrite the call argument. +keepInLifetimeExtendingContext(); EnsureImmediateInvocationInDefaultArgs Immediate(*this); ExprResult Res; + +// Rebuild CXXDefaultInitExpr might cause diagnostics. +SFINAETrap Trap(*this); cor3ntin wrote: And I don't think we should silence those, right? https://github.com/llvm/llvm-project/pull/97308 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)
@@ -5567,19 +5568,35 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) { ImmediateCallVisitor V(getASTContext()); if (!NestedDefaultChecking) V.TraverseDecl(Field); - if (V.HasImmediateCalls) { + + // CWG1815 + // Support lifetime extension of temporary created by aggregate + // initialization using a default member initializer. We should always rebuild + // the initializer if it contains any temporaries (if the initializer + // expression is an ExprWithCleanups). Then make sure the normal lifetime + // extension code recurses into the default initializer and does lifetime + // extension when warranted. + bool ContainsAnyTemporaries = + isa_and_present(Field->getInClassInitializer()); + if (V.HasImmediateCalls || InLifetimeExtendingContext || + ContainsAnyTemporaries) { cor3ntin wrote: Should that not be `V.HasImmediateCalls || (InLifetimeExtendingContext && ContainsAnyTemporaries)` ? https://github.com/llvm/llvm-project/pull/97308 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revisit the fix for the lambda within a type alias template decl (PR #89934)
@@ -91,15 +91,60 @@ void bar() { namespace GH82104 { -template int Zero = 0; +template int Value = sizeof...(D); -template -using T14 = decltype([]() { return Zero; }()); +template +using T14 = decltype([](auto Param) { + return Value + V + (int)sizeof(Param); +}("hello")); template using T15 = T14; static_assert(__is_same(T15, int)); +// FIXME: This still crashes because we can't extract template arguments T and U +// outside of the instantiation context of T16. +#if 0 +template +using T16 = decltype([](auto Param) requires (sizeof(Param) != 1 && sizeof...(U) > 0) { + return Value + sizeof(Param); +}); +static_assert(T16()(42) == 2 + sizeof(42)); +#endif zyn0217 wrote: It turns out to be an evaluation context that eventually becomes the lambda context declaration. Given that Matheus is going to refactor these codes shortly in the future, and we have not been correctly compiling this case for a long time (https://gcc.godbolt.org/z/sbYT1Pa91), I think I can delegate it to @mizvekov, and hopefully, he could fix the test here. https://github.com/llvm/llvm-project/pull/89934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revisit the fix for the lambda within a type alias template decl (PR #89934)
zyn0217 wrote: > We are missing a changelog entry though No release entry because this was intended to be a fix for 19 regression and we now want to backport it :) https://github.com/llvm/llvm-project/pull/89934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { zyn0217 wrote: Can you reference some wording here? Are those hardcoded names sufficient? https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
@@ -972,8 +972,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. cor3ntin wrote: I wonder if we could temporarily pretend that the declarations are equivalent while checking their constraint so that their canonical type matches. That way we could just do a normal parameter substitution, I think. Or maybe @mizvekov solution would be better. https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
@@ -972,8 +972,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the cor3ntin wrote: ```suggestion // However, as we are in the process of comparing potential re-declarations, // the canonical declaration is the declaration itself at this point. ``` https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/cor3ntin approved this pull request. LGTM. This fixes the bug, however we should explore a more robust solution https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
cor3ntin wrote: should we rename `SubstituteConstraintExpressionWithoutSatisfaction` to make it clear it only works to compare them? https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { + const LangOptions &Lang = PP.getLangOpts(); + const StringRef Name = II->getName(); + + if (Lang.CPlusPlus26) +return Name == "indeterminate"; + if (Lang.CPlusPlus23) +return Name == "assume"; zwuis wrote: It seems that `#define assume` will not trigger diagnostic in C++26. Do I misunderstand this code? https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
@@ -972,8 +972,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. zyn0217 wrote: > I wonder if we could temporarily pretend that the declarations are equivalent > while checking their constraint so that their canonical type matches. I tried that approach in https://github.com/llvm/llvm-project/commit/0727e47124af564826a22a718a64a1da79e6131d. While it works, I don't think I like it quite much because it looks unnatural/dirty to me. https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
zyn0217 wrote: > should we rename SubstituteConstraintExpressionWithoutSatisfaction to make it > clear it only works to compare them? Good idea. How about `SubstituteConstraintExpressionForEquivalenceChecking` then? We can rename it in the next PR. https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102131 >From aa99ac433c9d383bfca732c19e5082a555f64c2d Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Tue, 6 Aug 2024 20:08:43 +0800 Subject: [PATCH 1/3] [Clang][Concepts] Fix the constraint equivalence checking for TemplateTypeParmTypes --- clang/lib/Sema/SemaConcept.cpp| 11 +++-- .../SemaTemplate/concepts-out-of-line-def.cpp | 23 +++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..14a67f35a8f9f8 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -972,8 +972,15 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // Parameter packs should expand to a size-of-1 argument. + ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); + ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); +} std::optional ThisScope; diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index 0142efcdc3ee86..333187b0d74ad6 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -599,3 +599,26 @@ template unsigned long DerivedCollection::index() {} } // namespace GH72557 + +namespace GH101735 { + +template +concept True = true; + +template +class A { + template + void method(Ts&... ts) +requires requires (T t) { + { t.method(static_cast(ts)...) } -> True; +}; +}; + +template +template +void A::method(Ts&... ts) + requires requires (T t) { +{ t.method(static_cast(ts)...) } -> True; + } {} + +} >From 339ab57452ff2998f9b1d13a33d2ef1620a2a67c Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sun, 25 Aug 2024 10:32:30 +0800 Subject: [PATCH 2/3] Clarify the reason & add a FIXME --- clang/lib/Sema/SemaConcept.cpp | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 14a67f35a8f9f8..b83e0f094579d2 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -977,7 +977,22 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( ScopeForParameters.InstantiatedLocal(PVD, PVD); continue; } - // Parameter packs should expand to a size-of-1 argument. + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); } >From 811bfc9011adf48bb22cce3e0ece0f7539bd095c Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 26 Aug 2024 13:47:59 +0800 Subject: [PATCH 3/3] Apply Corentin's feedback Co-authored-by: cor3ntin --- clang/lib/Sema/SemaConcept.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index b83e0f094579d2..6e31cc6f87f2c5 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -983,8 +983,8 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // otherwise reference the AssociatedDecl of the template arguments, which // is, in this case, the template declaration. // - // However, as we're also calculating the redeclarations of the template, - // the canonical declarations thereof are actually themselves at the + // However, as we are in the process of comparing potential re-declarations, + // the canonical decl
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102131 >From aa99ac433c9d383bfca732c19e5082a555f64c2d Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Tue, 6 Aug 2024 20:08:43 +0800 Subject: [PATCH 1/4] [Clang][Concepts] Fix the constraint equivalence checking for TemplateTypeParmTypes --- clang/lib/Sema/SemaConcept.cpp| 11 +++-- .../SemaTemplate/concepts-out-of-line-def.cpp | 23 +++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..14a67f35a8f9f8 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -972,8 +972,15 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // Parameter packs should expand to a size-of-1 argument. + ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); + ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); +} std::optional ThisScope; diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index 0142efcdc3ee86..333187b0d74ad6 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -599,3 +599,26 @@ template unsigned long DerivedCollection::index() {} } // namespace GH72557 + +namespace GH101735 { + +template +concept True = true; + +template +class A { + template + void method(Ts&... ts) +requires requires (T t) { + { t.method(static_cast(ts)...) } -> True; +}; +}; + +template +template +void A::method(Ts&... ts) + requires requires (T t) { +{ t.method(static_cast(ts)...) } -> True; + } {} + +} >From 339ab57452ff2998f9b1d13a33d2ef1620a2a67c Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sun, 25 Aug 2024 10:32:30 +0800 Subject: [PATCH 2/4] Clarify the reason & add a FIXME --- clang/lib/Sema/SemaConcept.cpp | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 14a67f35a8f9f8..b83e0f094579d2 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -977,7 +977,22 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( ScopeForParameters.InstantiatedLocal(PVD, PVD); continue; } - // Parameter packs should expand to a size-of-1 argument. + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); } >From 811bfc9011adf48bb22cce3e0ece0f7539bd095c Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 26 Aug 2024 13:47:59 +0800 Subject: [PATCH 3/4] Apply Corentin's feedback Co-authored-by: cor3ntin --- clang/lib/Sema/SemaConcept.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index b83e0f094579d2..6e31cc6f87f2c5 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -983,8 +983,8 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // otherwise reference the AssociatedDecl of the template arguments, which // is, in this case, the template declaration. // - // However, as we're also calculating the redeclarations of the template, - // the canonical declarations thereof are actually themselves at the + // However, as we are in the process of comparing potential re-declarations, + // the canonical decl
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 3364284d87035eaac9662d345d4ddee2714f8fd7 811bfc9011adf48bb22cce3e0ece0f7539bd095c --extensions cpp -- clang/lib/Sema/SemaConcept.cpp clang/test/SemaTemplate/concepts-out-of-line-def.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 6e31cc6f87..1b8fd5bf70 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -983,10 +983,10 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // otherwise reference the AssociatedDecl of the template arguments, which // is, in this case, the template declaration. // - // However, as we are in the process of comparing potential re-declarations, - // the canonical declaration is the declaration itself at this point. - // moment. So if we didn't expand these packs, we would end up with an - // incorrect profile difference because we will be profiling the + // However, as we are in the process of comparing potential + // re-declarations, the canonical declaration is the declaration itself at + // this point. moment. So if we didn't expand these packs, we would end up + // with an incorrect profile difference because we will be profiling the // canonical types! // // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so `` https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { a-tarasyuk wrote: >From my, attribute names aren't typical language keywords, and only a specific >set defined by the standard should be disallowed. For example, `likely` and >`unlikely` should be permitted. Reusing attribute parsing doesn't seem >appropriate here. I haven't found a predefined list of standard attributes; if >there is one, I would appreciate it if you could direct me to it. Thanks https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/zwuis edited https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { cor3ntin wrote: `likely` is reserved, `likely()` is not. Also, as we support attributes in older language modes as extensions so we should take that into account. Does C has similar restrictions? https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { cor3ntin wrote: Can we tablegen that somehow? https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)
@@ -5421,34 +5635,139 @@ static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc, // the partial ordering is done: TemplateDeductionInfo Info(Loc); switch (TPOC) { - case TPOC_Call: -if (DeduceTemplateArguments(S, TemplateParams, Args2.data(), Args2.size(), -Args1.data(), Args1.size(), Info, Deduced, -TDF_None, /*PartialOrdering=*/true) != -TemplateDeductionResult::Success) + case TPOC_Call: { +llvm::SmallBitVector HasDeducedParam(Args2.size()); +if (DeduceTemplateArguments( +S, TemplateParams, Args2.data(), Args2.size(), Args1.data(), +Args1.size(), Info, Deduced, TDF_None, /*PartialOrdering=*/true, +/*HasDeducedAnyParam=*/nullptr, +&HasDeducedParam) != TemplateDeductionResult::Success) return false; -break; +SmallVector DeducedArgs(Deduced.begin(), + Deduced.end()); +Sema::InstantiatingTemplate Inst( +S, Info.getLocation(), FT2, DeducedArgs, +Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info); +if (Inst.isInvalid()) + return false; - case TPOC_Conversion: +bool AtLeastAsSpecialized = true; +S.runWithSufficientStackSpace(Info.getLocation(), [&] { + AtLeastAsSpecialized = + ::FinishTemplateArgumentDeduction( + S, FT2, Deduced, Info, + [&](Sema &S, FunctionTemplateDecl *FTD, + ArrayRef DeducedArgs) { +return ::DeduceForEachType( +S, TemplateParams, Args2.data(), Args2.size(), Args1.data(), +Args1.size(), Info, Deduced, +/*PartialOrdering=*/true, /*FinishingDeduction=*/true, +[&](Sema &S, TemplateParameterList *, int ParamIdx, +int ArgIdx, QualType P, QualType A, +TemplateDeductionInfo &Info, +SmallVectorImpl &Deduced, +bool) { + // As a provisional fix for a core issue that does not + // exist yet, only check the consistency of parameters + // which participated in deduction. We still try to + // substitute them though. cor3ntin wrote: I think it's fine to reference https://cplusplus.github.io/CWG/issues/2160.html https://github.com/llvm/llvm-project/pull/100692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr, return false; } +static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) { a-tarasyuk wrote: > Can we tablegen that somehow? @cor3ntin Oke, I'll check... https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)
@@ -1307,6 +1304,62 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, return TemplateDeductionResult::Success; } +/// Deduce the template arguments by comparing the list of parameter +/// types to the list of argument types, as in the parameter-type-lists of +/// function types (C++ [temp.deduct.type]p10). +/// +/// \param S The semantic analysis object within which we are deducing +/// +/// \param TemplateParams The template parameters that we are deducing +/// +/// \param Params The list of parameter types +/// +/// \param NumParams The number of types in \c Params +/// +/// \param Args The list of argument types +/// +/// \param NumArgs The number of types in \c Args +/// +/// \param Info information about the template argument deduction itself +/// +/// \param Deduced the deduced template arguments +/// +/// \param TDF bitwise OR of the TemplateDeductionFlags bits that describe +/// how template argument deduction is performed. +/// +/// \param PartialOrdering If true, we are performing template argument +/// deduction for during partial ordering for a call +/// (C++0x [temp.deduct.partial]). +/// +/// \returns the result of template argument deduction so far. Note that a +/// "success" result means that template argument deduction has not yet failed, +/// but it may still fail, later, for other reasons. +static TemplateDeductionResult DeduceTemplateArguments( +Sema &S, TemplateParameterList *TemplateParams, const QualType *Params, +unsigned NumParams, const QualType *Args, unsigned NumArgs, +TemplateDeductionInfo &Info, +SmallVectorImpl &Deduced, unsigned TDF, +bool PartialOrdering, bool *HasDeducedAnyParam, +llvm::SmallBitVector *HasDeducedParam) { cor3ntin wrote: I would suggest always passing a `SmallBitVector` in most cases checking its size is going to boil down to a popcount instruction anyway. I am happy for you to do that in a follow up, but I really would like to see it happen, these interfaces are becoming too unwieldy https://github.com/llvm/llvm-project/pull/100692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)
cor3ntin wrote: @mizvekov please avoid force pushing (prefer merging from main and push new commits) - otherwise github sometimes eat comments which makes review difficult. I previously mentioned that your changes to `getMoreSpecializedTemplate` probably needed explicit object parameters tests. I then realized that this was https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2834. Can you check what we do in this case? Thanks https://github.com/llvm/llvm-project/pull/100692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
@@ -972,8 +972,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. cor3ntin wrote: I think both approach are equally... in search of a better 3rd approach :D I like the Decl approach because it doesn't mess too much with substitution at all, the only thing that should be affected is profiling. So I am somewhat more confident about its correctness, if that makes sense. Any preference @mizvekov ? https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e6974da - [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131)
Author: Younan Zhang Date: 2024-08-26T14:30:26+08:00 New Revision: e6974daa7bc100c8b88057d50f3ec3eca7282243 URL: https://github.com/llvm/llvm-project/commit/e6974daa7bc100c8b88057d50f3ec3eca7282243 DIFF: https://github.com/llvm/llvm-project/commit/e6974daa7bc100c8b88057d50f3ec3eca7282243.diff LOG: [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131) We established an instantiation scope in order for constraint equivalence checking to properly map the uninstantiated parameters. That mechanism mapped even packs to themselves. Consequently, parameter packs e.g. appearing in a function call, were not expanded. So they would end up becoming `SubstTemplateTypeParmPackType`s that circularly depend on the canonical declaration of the function template, which is not yet determined, hence the spurious error. No release note as I plan to backport it to 19. Fixes https://github.com/llvm/llvm-project/issues/101735 - Co-authored-by: cor3ntin Added: Modified: clang/lib/Sema/SemaConcept.cpp clang/test/SemaTemplate/concepts-out-of-line-def.cpp Removed: diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index de24bbe7eb99ce..86d6f308a51cc2 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -977,8 +977,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we are in the process of comparing potential + // re-declarations, the canonical declaration is the declaration itself at + // this point. So if we didn't expand these packs, we would end up with an + // incorrect profile diff erence because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. + ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); + ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); +} std::optional ThisScope; diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index 0142efcdc3ee86..333187b0d74ad6 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -599,3 +599,26 @@ template unsigned long DerivedCollection::index() {} } // namespace GH72557 + +namespace GH101735 { + +template +concept True = true; + +template +class A { + template + void method(Ts&... ts) +requires requires (T t) { + { t.method(static_cast(ts)...) } -> True; +}; +}; + +template +template +void A::method(Ts&... ts) + requires requires (T t) { +{ t.method(static_cast(ts)...) } -> True; + } {} + +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/zyn0217 closed https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/101469 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)
cor3ntin wrote: Does it makes sense to also support function templates? For example, my understanding is that specializing `is_pointer_interconvertible_with_class()` would be UB https://github.com/llvm/llvm-project/pull/101469 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
zyn0217 wrote: /cherry-pick e6974daa7 https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
llvmbot wrote: >/cherry-pick e6974daa7 Error: Command failed due to missing milestone. https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)
@@ -0,0 +1,120 @@ +//===--- IncorrectEnableSharedFromThisCheck.cpp - clang-tidy --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "IncorrectEnableSharedFromThisCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/SmallPtrSet.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(translationUnitDecl(), this); +} + +void IncorrectEnableSharedFromThisCheck::check( +const MatchFinder::MatchResult &Result) { + + class Visitor : public RecursiveASTVisitor { +IncorrectEnableSharedFromThisCheck &Check; +llvm::SmallPtrSet EnableSharedClassSet; + + public: +explicit Visitor(IncorrectEnableSharedFromThisCheck &Check) +: Check(Check) {} + +bool VisitCXXRecordDecl(CXXRecordDecl *RDecl) { + for (const auto &Base : RDecl->bases()) { +VisitCXXBaseSpecifier(Base, RDecl); + } + for (const auto &Base : RDecl->bases()) { +const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl(); +if (BaseType && BaseType->getQualifiedNameAsString() == +"std::enable_shared_from_this") { + EnableSharedClassSet.insert(RDecl->getCanonicalDecl()); + return true; +} + } + return true; +} + +bool VisitCXXBaseSpecifier(const CXXBaseSpecifier &Base, + CXXRecordDecl *RDecl) { + const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl(); + const clang::AccessSpecifier AccessSpec = Base.getAccessSpecifier(); + + if (BaseType && + BaseType->getQualifiedNameAsString() == "enable_shared_from_this") { +if (AccessSpec == clang::AS_public) { + const SourceLocation InsertLocation = Base.getBaseTypeLoc(); + const FixItHint Hint = FixItHint::CreateInsertion(InsertLocation, "std::"); MichelleCDjunaidi wrote: removed std::check. https://github.com/llvm/llvm-project/pull/102299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)
https://github.com/MichelleCDjunaidi edited https://github.com/llvm/llvm-project/pull/102299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/zyn0217 milestoned https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
zyn0217 wrote: /cherry-pick e6974daa https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
@@ -972,8 +972,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. zyn0217 wrote: > the only thing that should be affected is profiling. Hmm, I see your point... https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)
MichelleCDjunaidi wrote: @5chmidti Thanks for the pointers, I've implemented your suggestion. For future knowledge, what do you mean by > it is technically not in the format of the RecursiveASTVisitor and may be > confusing ? Is there a guide that can point out what format Visit should have? https://github.com/llvm/llvm-project/pull/102299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
llvmbot wrote: /pull-request llvm/llvm-project#106043 https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix misalignments of pointers in angle brackets (PR #106013)
https://github.com/owenca milestoned https://github.com/llvm/llvm-project/pull/106013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits