Skip to content

Commit bffbe9a

Browse files
[clang] Correct behavior of LLVM_UNREACHABLE_OPTIMIZE=OFF for Release builds (#68284)
# Codegen ### Before ```c++ AArch64SVEPcsAttr *AArch64SVEPcsAttr::CreateImplicit(ASTContext &Ctx, SourceRange Range, Spelling S) { AttributeCommonInfo I(Range, NoSemaHandlerAttribute, ( S == GNU_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, GNU_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} : S == CXX11_clang_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_CXX11, CXX11_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} : S == C23_clang_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_C23, C23_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} : (llvm_unreachable("Unknown attribute spelling!"), AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, 0, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}))); return CreateImplicit(Ctx, I); } ``` ### After ```c++ AArch64SVEPcsAttr *AArch64SVEPcsAttr::CreateImplicit(ASTContext &Ctx, SourceRange Range, Spelling S) { AttributeCommonInfo I(Range, NoSemaHandlerAttribute, [&]() { switch (S) { case GNU_aarch64_sve_pcs: return AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, GNU_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; case CXX11_clang_aarch64_sve_pcs: return AttributeCommonInfo::Form{AttributeCommonInfo::AS_CXX11, CXX11_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; case C23_clang_aarch64_sve_pcs: return AttributeCommonInfo::Form{AttributeCommonInfo::AS_C23, C23_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; default: llvm_unreachable("Unknown attribute spelling!"); return AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, 0, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; } }()); return CreateImplicit(Ctx, I); } ``` Fixes #68237
1 parent a50e63b commit bffbe9a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ Bug Fixes in This Version
343343
- Fix a crash when evaluating value-dependent structured binding
344344
variables at compile time.
345345
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
346+
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
347+
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
346348

347349
Bug Fixes to Compiler Builtins
348350
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,23 +2690,28 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
26902690
OS << ", ";
26912691
emitFormInitializer(OS, Spellings[0], "0");
26922692
} else {
2693-
OS << ", (\n";
2693+
OS << ", [&]() {\n";
2694+
OS << " switch (S) {\n";
26942695
std::set<std::string> Uniques;
26952696
unsigned Idx = 0;
26962697
for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
26972698
++I, ++Idx) {
26982699
const FlattenedSpelling &S = *I;
26992700
const auto &Name = SemanticToSyntacticMap[Idx];
27002701
if (Uniques.insert(Name).second) {
2701-
OS << " S == " << Name << " ? AttributeCommonInfo::Form";
2702+
OS << " case " << Name << ":\n";
2703+
OS << " return AttributeCommonInfo::Form";
27022704
emitFormInitializer(OS, S, Name);
2703-
OS << " :\n";
2705+
OS << ";\n";
27042706
}
27052707
}
2706-
OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), "
2707-
<< " AttributeCommonInfo::Form";
2708+
OS << " default:\n";
2709+
OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n"
2710+
<< " return AttributeCommonInfo::Form";
27082711
emitFormInitializer(OS, Spellings[0], "0");
2709-
OS << "))";
2712+
OS << ";\n"
2713+
<< " }\n"
2714+
<< " }()";
27102715
}
27112716

27122717
OS << ");\n";

0 commit comments

Comments
 (0)