From e7b3b94cf500c5c4dc1bed6dd47e031d73678c86 Mon Sep 17 00:00:00 2001 From: Arvind Mukund Date: Thu, 5 Oct 2023 12:01:56 -0700 Subject: [PATCH] [clang] Correct behavior of `LLVM_UNREACHABLE_OPTIMIZE=OFF` for `Release` builds (#68284) ```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); } ``` ```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 https://github.com/llvm/llvm-project/issues/68237 Conflicts: clang/docs/ReleaseNotes.rst --- clang/docs/ReleaseNotes.rst | 2 ++ clang/utils/TableGen/ClangAttrEmitter.cpp | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ee3794f7fc61..3323c6ceb2bc 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -717,6 +717,8 @@ Bug Fixes in This Version virtual member functions even if the target required a greater function alignment and/or did not have function pointers which point to function entry points (i.e., uses function descriptor objects instead). +- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF`` + cannot be used with ``Release`` mode builds. (`#68237 `_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 8ef728f86c6b..b5813c6abc2b 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -2639,7 +2639,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; @@ -2647,15 +2648,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";