From 8598d5f4cfad4f3887ec40b7c3d21e385f731d9d Mon Sep 17 00:00:00 2001 From: Arvind Mukund Date: Wed, 4 Oct 2023 22:25:08 -0700 Subject: [PATCH 1/4] Correct unreachable hint in release mode When LLVM_UNREACHABLE_OPTIMIZE is turned off during release mode, a `do { BUILTIN_TRAP; BUILTIN_UNREACHABLE; } while(0)` is emitted this causes the ternary operator to not work as expected. Correct this behavior such that it works in all modes. Tests: * LLVM_UNREACHABLE_OPTIMIZE=[ON|OFF] works in both `Release` and `Debug` modes * Lambdas on release mode are inlined / similar lambdas are merged. Signed-off-by: Arvind Mukund --- clang/utils/TableGen/ClangAttrEmitter.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index ffada02ac4d30a..6a821463aa9f0f 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -2690,7 +2690,8 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS, OS << ", "; emitFormInitializer(OS, Spellings[0], "0"); } else { - OS << ", (\n"; + OS << ", [&]() {\n"; + OS << " switch (S) {\n"; std::set Uniques; unsigned Idx = 0; for (auto I = Spellings.begin(), E = Spellings.end(); I != E; @@ -2698,15 +2699,19 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS, const FlattenedSpelling &S = *I; const auto &Name = SemanticToSyntacticMap[Idx]; if (Uniques.insert(Name).second) { - OS << " S == " << Name << " ? AttributeCommonInfo::Form"; + OS << " case " << Name << ":\n"; + OS << " return AttributeCommonInfo::Form"; emitFormInitializer(OS, S, Name); - OS << " :\n"; + OS << ";\n"; } } - OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), " - << " AttributeCommonInfo::Form"; + OS << " default:\n"; + OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n" + << " return AttributeCommonInfo::Form"; emitFormInitializer(OS, Spellings[0], "0"); - OS << "))"; + OS << ";\n" + << " }\n" + << " }()"; } OS << ");\n"; From 0a4442b0a3baac993b8e3ca98fe4389b0e0e577d Mon Sep 17 00:00:00 2001 From: Arvind Mukund Date: Wed, 4 Oct 2023 22:34:32 -0700 Subject: [PATCH 2/4] Remove extra space after `return` Signed-off-by: Arvind Mukund --- clang/utils/TableGen/ClangAttrEmitter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 6a821463aa9f0f..f2a6c1dfcf2fcc 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -2700,7 +2700,7 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS, const auto &Name = SemanticToSyntacticMap[Idx]; if (Uniques.insert(Name).second) { OS << " case " << Name << ":\n"; - OS << " return AttributeCommonInfo::Form"; + OS << " return AttributeCommonInfo::Form"; emitFormInitializer(OS, S, Name); OS << ";\n"; } From df0287c44856a08badc6ce3051c4cd6963662db1 Mon Sep 17 00:00:00 2001 From: Arvind Mukund Date: Thu, 5 Oct 2023 09:53:51 -0700 Subject: [PATCH 3/4] Add this bug fix to clang's release notes Signed-off-by: Arvind Mukund --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7b22f3c6842c9f..29f3e18fc59fc2 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -343,6 +343,8 @@ Bug Fixes in This Version - Fix a crash when evaluating value-dependent structured binding variables at compile time. Fixes (`#67690 `_) +- Fixes a regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF`` cannot be used + with ``Release`` mode builds. (`#68237 `_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 8ffd966ed5c3bee7da9251df921e06f8f2f1e4bc Mon Sep 17 00:00:00 2001 From: Arvind Mukund Date: Thu, 5 Oct 2023 11:50:06 -0700 Subject: [PATCH 4/4] Define the regressed clang version in the release notes --- clang/docs/ReleaseNotes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 29f3e18fc59fc2..ae67a783c2fa2d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -343,8 +343,8 @@ Bug Fixes in This Version - Fix a crash when evaluating value-dependent structured binding variables at compile time. Fixes (`#67690 `_) -- Fixes a regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF`` cannot be used - with ``Release`` mode builds. (`#68237 `_) +- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF`` + cannot be used with ``Release`` mode builds. (`#68237 `_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^