From: Erich Keane Date: Tue, 17 Sep 2019 14:11:51 +0000 (+0000) Subject: Add SpellingNotCalculated to Attribute Enums to suppress UBSan warnings X-Git-Tag: llvmorg-11-init~9005 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68b0977e646abda3254a1eed123f75183b4aad3d;p=platform%2Fupstream%2Fllvm.git Add SpellingNotCalculated to Attribute Enums to suppress UBSan warnings UBSan downstreams noticed that the assignment of SpellingNotCalculated to the spellings caused warnings. llvm-svn: 372124 --- diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 7ad8b52..efa7f43 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -615,6 +615,8 @@ void MicrosoftCXXNameMangler::mangleMemberDataPointer(const CXXRecordDecl *RD, case MSInheritanceAttr::Keyword_multiple_inheritance: Code = '0'; break; case MSInheritanceAttr::Keyword_virtual_inheritance: Code = 'F'; break; case MSInheritanceAttr::Keyword_unspecified_inheritance: Code = 'G'; break; + case MSInheritanceAttr::SpellingNotCalculated: + llvm_unreachable("not reachable"); } Out << '$' << Code; @@ -646,6 +648,8 @@ MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const CXXRecordDecl *RD, case MSInheritanceAttr::Keyword_multiple_inheritance: Code = 'H'; break; case MSInheritanceAttr::Keyword_virtual_inheritance: Code = 'I'; break; case MSInheritanceAttr::Keyword_unspecified_inheritance: Code = 'J'; break; + case MSInheritanceAttr::SpellingNotCalculated: + llvm_unreachable("not reachable"); } // If non-virtual, mangle the name. If virtual, mangle as a virtual memptr diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index e36f6932..e656fe6 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2711,6 +2711,8 @@ llvm::DIType *CGDebugInfo::CreateType(const MemberPointerType *Ty, break; case MSInheritanceAttr::Keyword_unspecified_inheritance: break; + case MSInheritanceAttr::SpellingNotCalculated: + llvm_unreachable("Spelling not yet calculated"); } } } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 019ac5ea..c892c62 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1633,6 +1633,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { case OpenCLAccessAttr::Keyword_read_only: \ Result = Context.Id##ROTy; \ break; \ + case OpenCLAccessAttr::SpellingNotCalculated: \ + llvm_unreachable("Spelling not yet calculated"); \ } \ break; #include "clang/Basic/OpenCLImageTypes.def" diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 1221842..55c2901 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -1596,6 +1596,13 @@ CreateSemanticSpellings(const std::vector &Spellings, std::string Ret(" enum Spelling {\n"); std::set Uniques; unsigned Idx = 0; + + // If we have a need to have this many spellings we likely need to add an + // extra bit to the SpellingIndex in AttributeCommonInfo, then increase the + // value of SpellingNotCalculated there and here. + assert(Spellings.size() < 15 && + "Too many spellings, would step on SpellingNotCalculated in " + "AttributeCommonInfo"); for (auto I = Spellings.begin(), E = Spellings.end(); I != E; ++I, ++Idx) { const FlattenedSpelling &S = *I; const std::string &Variety = S.variety(); @@ -1629,6 +1636,7 @@ CreateSemanticSpellings(const std::vector &Spellings, // enumerator. Ret += " " + EnumName + " = " + llvm::utostr(Idx); } + Ret += ",\n SpellingNotCalculated = 15\n"; Ret += "\n };\n\n"; return Ret; }