https://github.com/mcbarton updated https://github.com/llvm/llvm-project/pull/146786
>From d528fe6474cf233ed024a1479ede12545e59b4c2 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbar...@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:17:30 +0100 Subject: [PATCH] Add __attribute__((visibility("default"))) attribute to stop symbols being hidden when linking clangInterpreter library to other libraries during Emscripten build Currently CppInterOp links its Emscripten shared library to the Emscripten static library libclangInterpreter.a . Certain symbols get hidden in libclangInterOp.a due to the -fvisibility-inlines-hidden flag when building an Emscripten build of llvm. This causes the CppInterOp to have to manually export these in a non Emscripten recommended way (see https://github.com/compiler-research/CppInterOp/blob/main/lib/CppInterOp/exports.ld ). This patch would allow us to avoid this method, by marking these symbols are visible, instead of hidden. --- clang/lib/AST/ASTContext.cpp | 8 ++++---- clang/lib/AST/Decl.cpp | 11 ++++++----- clang/lib/AST/DeclBase.cpp | 15 ++++++++------- clang/lib/AST/DeclTemplate.cpp | 5 ++++- clang/lib/AST/Mangle.cpp | 5 +++-- clang/lib/AST/Type.cpp | 9 ++++++--- clang/lib/Interpreter/Interpreter.cpp | 10 +++++++--- clang/lib/Interpreter/InterpreterValuePrinter.cpp | 9 +++++---- clang/lib/Sema/SemaDeclCXX.cpp | 3 ++- llvm/include/llvm/ADT/SmallVector.h | 2 +- llvm/lib/Support/APInt.cpp | 12 +++++++----- llvm/lib/Support/Debug.cpp | 3 ++- llvm/lib/Support/Error.cpp | 6 ++++-- llvm/lib/Support/ErrorHandling.cpp | 5 +++-- llvm/lib/Support/MemAlloc.cpp | 2 ++ llvm/lib/Support/StringMap.cpp | 11 +++++++---- llvm/lib/Support/Valgrind.cpp | 11 ++++------- llvm/lib/Support/raw_ostream.cpp | 14 +++++++------- 18 files changed, 82 insertions(+), 59 deletions(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b13bdd5642977..d79dac5558894 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3895,7 +3895,7 @@ void ASTContext::adjustExceptionSpec( /// getComplexType - Return the uniqued reference to the type for a complex /// number with the specified element type. -QualType ASTContext::getComplexType(QualType T) const { +LLVM_ABI QualType ASTContext::getComplexType(QualType T) const { // Unique pointers, to guarantee there is only one pointer of a particular // structure. llvm::FoldingSetNodeID ID; @@ -4079,7 +4079,7 @@ QualType ASTContext::getBlockPointerType(QualType T) const { /// getLValueReferenceType - Return the uniqued reference to the type for an /// lvalue reference to the specified type. -QualType +LLVM_ABI QualType ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { assert((!T->isPlaceholderType() || T->isSpecificPlaceholderType(BuiltinType::UnknownAny)) && @@ -5251,7 +5251,7 @@ QualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl, /// getTypeDeclType - Return the unique reference to the type for the /// specified type declaration. -QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { +LLVM_ABI QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { assert(Decl && "Passed null for Decl param"); assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); @@ -13125,7 +13125,7 @@ VTableContextBase *ASTContext::getVTableContext() { return VTContext.get(); } -MangleContext *ASTContext::createMangleContext(const TargetInfo *T) { +LLVM_ABI MangleContext *ASTContext::createMangleContext(const TargetInfo *T) { if (!T) T = Target; switch (T->getCXXABI().getKind()) { diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 5cdf75d71e4d7..ac728295a7c26 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -59,6 +59,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Triple.h" @@ -2255,7 +2256,7 @@ bool VarDecl::isInExternCXXContext() const { VarDecl *VarDecl::getCanonicalDecl() { return getFirstDecl(); } -VarDecl::DefinitionKind +LLVM_ABI VarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition(ASTContext &C) const { if (isThisDeclarationADemotedDefinition()) return DeclarationOnly; @@ -3763,7 +3764,7 @@ unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const { /// getNumParams - Return the number of parameters this function must have /// based on its FunctionType. This is the length of the ParamInfo array /// after it has been created. -unsigned FunctionDecl::getNumParams() const { +LLVM_ABI unsigned FunctionDecl::getNumParams() const { const auto *FPT = getType()->getAs<FunctionProtoType>(); return FPT ? FPT->getNumParams() : 0; } @@ -4200,7 +4201,7 @@ bool FunctionDecl::isTemplateInstantiation() const { return clang::isTemplateInstantiation(getTemplateSpecializationKind()); } -FunctionDecl * +LLVM_ABI FunctionDecl * FunctionDecl::getTemplateInstantiationPattern(bool ForDefinition) const { // If this is a generic lambda call operator specialization, its // instantiation pattern is always its primary template's pattern @@ -4265,7 +4266,7 @@ FunctionDecl::getTemplateSpecializationInfo() const { TemplateOrSpecialization); } -const TemplateArgumentList * +LLVM_ABI const TemplateArgumentList * FunctionDecl::getTemplateSpecializationArgs() const { if (FunctionTemplateSpecializationInfo *Info = dyn_cast_if_present<FunctionTemplateSpecializationInfo *>( @@ -5143,7 +5144,7 @@ RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, return R; } -bool RecordDecl::isInjectedClassName() const { +LLVM_ABI bool RecordDecl::isInjectedClassName() const { return isImplicit() && getDeclName() && getDeclContext()->isRecord() && cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName(); } diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 13c46fdbff96a..5cd4639de979e 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -37,6 +37,7 @@ #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/VersionTuple.h" @@ -526,7 +527,7 @@ TranslationUnitDecl *Decl::getTranslationUnitDecl() { return cast<TranslationUnitDecl>(DC); } -ASTContext &Decl::getASTContext() const { +LLVM_ABI ASTContext &Decl::getASTContext() const { return getTranslationUnitDecl()->getASTContext(); } @@ -613,7 +614,7 @@ ExternalSourceSymbolAttr *Decl::getExternalSourceSymbolAttr() const { return nullptr; } -bool Decl::hasDefiningAttr() const { +LLVM_ABI bool Decl::hasDefiningAttr() const { return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>() || hasAttr<LoaderUninitializedAttr>(); } @@ -1047,7 +1048,7 @@ void Decl::addAttr(Attr *A) { Attrs.insert(I, A); } -const AttrVec &Decl::getAttrs() const { +LLVM_ABI const AttrVec &Decl::getAttrs() const { assert(HasAttrs && "No attrs to get!"); return getASTContext().getDeclAttrs(this); } @@ -1065,7 +1066,7 @@ Decl *Decl::castFromDeclContext (const DeclContext *D) { } } -DeclContext *Decl::castToDeclContext(const Decl *D) { +LLVM_ABI DeclContext *Decl::castToDeclContext(const Decl *D) { Decl::Kind DK = D->getKind(); switch(DK) { #define DECL(NAME, BASE) @@ -1291,7 +1292,7 @@ DeclContext::DeclContext(Decl::Kind K) { setUseQualifiedLookup(false); } -bool DeclContext::classof(const Decl *D) { +LLVM_ABI bool DeclContext::classof(const Decl *D) { Decl::Kind DK = D->getKind(); switch (DK) { #define DECL(NAME, BASE) @@ -1662,7 +1663,7 @@ ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC, return List.getLookupResult(); } -DeclContext::decl_iterator DeclContext::decls_begin() const { +LLVM_ABI DeclContext::decl_iterator DeclContext::decls_begin() const { if (hasExternalLexicalStorage()) LoadLexicalDeclsFromExternalStorage(); return decl_iterator(FirstDecl); @@ -1891,7 +1892,7 @@ void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) { } } -DeclContext::lookup_result +LLVM_ABI DeclContext::lookup_result DeclContext::lookup(DeclarationName Name) const { // For transparent DeclContext, we should lookup in their enclosing context. if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export) diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 5035f2d33b0a1..db81fe450eccc 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -31,6 +31,7 @@ #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> #include <optional> @@ -549,6 +550,7 @@ void ClassTemplateDecl::LoadLazySpecializations( loadLazySpecializationsImpl(OnlyPartial); } +LLVM_ABI llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & ClassTemplateDecl::getSpecializations() const { LoadLazySpecializations(); @@ -1451,7 +1453,8 @@ void VarTemplateSpecializationDecl::getNameForDiagnostic( } } -VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { +LLVM_ABI VarTemplateDecl * +VarTemplateSpecializationDecl::getSpecializedTemplate() const { if (const auto *PartialSpec = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) return PartialSpec->PartialSpecialization->getSpecializedTemplate(); diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index 9652fdbc4e125..b54f9cd9f17bd 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -23,6 +23,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Mangler.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" @@ -118,7 +119,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context, } } -bool MangleContext::shouldMangleDeclName(const NamedDecl *D) { +LLVM_ABI bool MangleContext::shouldMangleDeclName(const NamedDecl *D) { const ASTContext &ASTContext = getASTContext(); CCMangling CC = getCallingConvMangling(ASTContext, D); @@ -152,7 +153,7 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl *D) { return shouldMangleCXXName(D); } -void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) { +LLVM_ABI void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) { const ASTContext &ASTContext = getASTContext(); const NamedDecl *D = cast<NamedDecl>(GD.getDecl()); diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index e5a1ab2ff8906..22e5ad236df1c 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -44,6 +44,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include <algorithm> @@ -650,7 +651,7 @@ template <> const CountAttributedType *Type::getAs() const { /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic /// sugar off the given type. This should produce an object of the /// same dynamic type as the canonical type. -const Type *Type::getUnqualifiedDesugaredType() const { +LLVM_ABI const Type *Type::getUnqualifiedDesugaredType() const { const Type *Cur = this; while (true) { @@ -2302,7 +2303,7 @@ bool Type::hasUnsignedIntegerRepresentation() const { return isUnsignedIntegerOrEnumerationType(); } -bool Type::isFloatingType() const { +LLVM_ABI bool Type::isFloatingType() const { if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) return BT->isFloatingPoint(); if (const auto *CT = dyn_cast<ComplexType>(CanonicalType)) @@ -4227,7 +4228,9 @@ static TagDecl *getInterestingTagDecl(TagDecl *decl) { return decl; } -TagDecl *TagType::getDecl() const { return getInterestingTagDecl(decl); } +LLVM_ABI TagDecl *TagType::getDecl() const { + return getInterestingTagDecl(decl); +} bool TagType::isBeingDefined() const { return getDecl()->isBeingDefined(); } diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 2f110659d19a4..684565c8fc7d9 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -49,6 +49,7 @@ #include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h" #include "llvm/ExecutionEngine/Orc/LLJIT.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" @@ -194,6 +195,7 @@ IncrementalCompilerBuilder::create(std::string TT, return CreateCI(**ErrOrCC1Args); } +LLVM_ABI llvm::Expected<std::unique_ptr<CompilerInstance>> IncrementalCompilerBuilder::CreateCpp() { std::vector<const char *> Argv; @@ -524,7 +526,9 @@ const CompilerInstance *Interpreter::getCompilerInstance() const { return CI.get(); } -CompilerInstance *Interpreter::getCompilerInstance() { return CI.get(); } +LLVM_ABI CompilerInstance *Interpreter::getCompilerInstance() { + return CI.get(); +} llvm::Expected<llvm::orc::LLJIT &> Interpreter::getExecutionEngine() { if (!IncrExecutor) { @@ -577,7 +581,7 @@ Interpreter::RegisterPTU(TranslationUnitDecl *TU, return LastPTU; } -llvm::Expected<PartialTranslationUnit &> +LLVM_ABI llvm::Expected<PartialTranslationUnit &> Interpreter::Parse(llvm::StringRef Code) { // If we have a device parser, parse it first. The generated code will be // included in the host compilation @@ -673,7 +677,7 @@ llvm::Error Interpreter::CreateExecutor() { void Interpreter::ResetExecutor() { IncrExecutor.reset(); } -llvm::Error Interpreter::Execute(PartialTranslationUnit &T) { +LLVM_ABI llvm::Error Interpreter::Execute(PartialTranslationUnit &T) { assert(T.TheModule); LLVM_DEBUG( llvm::dbgs() << "execute-ptu " diff --git a/clang/lib/Interpreter/InterpreterValuePrinter.cpp b/clang/lib/Interpreter/InterpreterValuePrinter.cpp index 3e7e32b2e8557..fcfdac7742e6e 100644 --- a/clang/lib/Interpreter/InterpreterValuePrinter.cpp +++ b/clang/lib/Interpreter/InterpreterValuePrinter.cpp @@ -20,7 +20,7 @@ #include "clang/Interpreter/Value.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Sema.h" - +#include "llvm/Support/Compiler.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" @@ -300,7 +300,7 @@ llvm::Expected<Expr *> Interpreter::ExtractValueFromExpr(Expr *E) { using namespace clang; // Temporary rvalue struct that need special care. -REPL_EXTERNAL_VISIBILITY void * +REPL_EXTERNAL_VISIBILITY LLVM_ABI void * __clang_Interpreter_SetValueWithAlloc(void *This, void *OutVal, void *OpaqueType) { Value &VRef = *(Value *)OutVal; @@ -308,8 +308,9 @@ __clang_Interpreter_SetValueWithAlloc(void *This, void *OutVal, return VRef.getPtr(); } -extern "C" void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc( - void *This, void *OutVal, void *OpaqueType, ...) { +extern "C" LLVM_ABI void REPL_EXTERNAL_VISIBILITY +__clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType, + ...) { Value &VRef = *(Value *)OutVal; Interpreter *I = static_cast<Interpreter *>(This); VRef = Value(I, OpaqueType); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index e8c65025bfe6d..cb8421277cf7e 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -50,6 +50,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/SaveAndRestore.h" #include <map> @@ -11959,7 +11960,7 @@ EnumDecl *Sema::getStdAlignValT() const { return cast_or_null<EnumDecl>(StdAlignValT.get(Context.getExternalSource())); } -NamespaceDecl *Sema::getStdNamespace() const { +LLVM_ABI NamespaceDecl *Sema::getStdNamespace() const { return cast_or_null<NamespaceDecl>( StdNamespace.get(Context.getExternalSource())); } diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index 0b8bb48b8fe5e..34ad51a422b6b 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -86,7 +86,7 @@ template <class Size_T> class SmallVectorBase { /// capacity for. /// /// This does not construct or destroy any elements in the vector. - void set_size(size_t N) { + LLVM_ABI void set_size(size_t N) { assert(N <= capacity()); // implies no overflow in assignment Size = static_cast<Size_T>(N); } diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 954af7fff92a8..09572b716770a 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/bit.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/Alignment.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" @@ -104,7 +105,8 @@ void APInt::initFromArray(ArrayRef<uint64_t> bigVal) { clearUnusedBits(); } -APInt::APInt(unsigned numBits, ArrayRef<uint64_t> bigVal) : BitWidth(numBits) { +LLVM_ABI APInt::APInt(unsigned numBits, ArrayRef<uint64_t> bigVal) + : BitWidth(numBits) { initFromArray(bigVal); } @@ -281,7 +283,7 @@ bool APInt::equalSlowCase(const APInt &RHS) const { return std::equal(U.pVal, U.pVal + getNumWords(), RHS.U.pVal); } -int APInt::compare(const APInt& RHS) const { +LLVM_ABI int APInt::compare(const APInt &RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be same for comparison"); if (isSingleWord()) return U.VAL < RHS.U.VAL ? -1 : U.VAL > RHS.U.VAL; @@ -289,7 +291,7 @@ int APInt::compare(const APInt& RHS) const { return tcCompare(U.pVal, RHS.U.pVal, getNumWords()); } -int APInt::compareSigned(const APInt& RHS) const { +LLVM_ABI int APInt::compareSigned(const APInt &RHS) const { assert(BitWidth == RHS.BitWidth && "Bit widths must be same for comparison"); if (isSingleWord()) { int64_t lhsSext = SignExtend64(U.VAL, BitWidth); @@ -982,7 +984,7 @@ APInt APInt::truncSSat(unsigned width) const { } // Sign extend to a new width. -APInt APInt::sext(unsigned Width) const { +LLVM_ABI APInt APInt::sext(unsigned Width) const { assert(Width >= BitWidth && "Invalid APInt SignExtend request"); if (Width <= APINT_BITS_PER_WORD) @@ -1009,7 +1011,7 @@ APInt APInt::sext(unsigned Width) const { } // Zero extend to a new width. -APInt APInt::zext(unsigned width) const { +LLVM_ABI APInt APInt::zext(unsigned width) const { assert(width >= BitWidth && "Invalid APInt ZeroExtend request"); if (width <= APINT_BITS_PER_WORD) diff --git a/llvm/lib/Support/Debug.cpp b/llvm/lib/Support/Debug.cpp index 5bb04d0c22998..227cf7533d682 100644 --- a/llvm/lib/Support/Debug.cpp +++ b/llvm/lib/Support/Debug.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/circular_raw_ostream.h" @@ -159,7 +160,7 @@ static void debug_user_sig_handler(void *Cookie) { } /// dbgs - Return a circular-buffered debug stream. -raw_ostream &llvm::dbgs() { +LLVM_ABI raw_ostream &llvm::dbgs() { // Do one-time initialization in a thread-safe way. static struct dbgstream { circular_raw_ostream strm; diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp index d168b462a6eb2..6b3da3e09ffe9 100644 --- a/llvm/lib/Support/Error.cpp +++ b/llvm/lib/Support/Error.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include <system_error> @@ -62,7 +63,8 @@ char ECError::ID = 0; char StringError::ID = 0; char FileError::ID = 0; -void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) { +LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, + Twine ErrorBanner) { if (!E) return; OS << ErrorBanner; @@ -125,7 +127,7 @@ std::error_code errorToErrorCode(Error Err) { } #if LLVM_ENABLE_ABI_BREAKING_CHECKS -void Error::fatalUncheckedError() const { +LLVM_ABI void Error::fatalUncheckedError() const { dbgs() << "Program aborted due to an unhandled Error:\n"; if (getPtr()) { getPtr()->log(dbgs()); diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp index cc16f2037ea58..9964c30dfe1c2 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/Config/config.h" #include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" @@ -219,8 +220,8 @@ void llvm::install_out_of_memory_new_handler() { } #endif -void llvm::llvm_unreachable_internal(const char *msg, const char *file, - unsigned line) { +LLVM_ABI void llvm::llvm_unreachable_internal(const char *msg, const char *file, + unsigned line) { // This code intentionally doesn't call the ErrorHandler callback, because // llvm_unreachable is intended to be used to indicate "impossible" // situations, and not legitimate runtime errors. diff --git a/llvm/lib/Support/MemAlloc.cpp b/llvm/lib/Support/MemAlloc.cpp index 6adc9abd75c5b..fa0cfd9c50b1e 100644 --- a/llvm/lib/Support/MemAlloc.cpp +++ b/llvm/lib/Support/MemAlloc.cpp @@ -7,10 +7,12 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/MemAlloc.h" +#include "llvm/Support/Compiler.h" #include <new> // These are out of line to have __cpp_aligned_new not affect ABI. +LLVM_ABI LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * llvm::allocate_buffer(size_t Size, size_t Alignment) { void *Result = ::operator new(Size, diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp index 432e1fc343f1f..072154c194a81 100644 --- a/llvm/lib/Support/StringMap.cpp +++ b/llvm/lib/Support/StringMap.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/StringMap.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/ReverseIteration.h" #include "llvm/Support/xxhash.h" @@ -43,7 +44,9 @@ static inline unsigned *getHashTable(StringMapEntryBase **TheTable, return reinterpret_cast<unsigned *>(TheTable + NumBuckets + 1); } -uint32_t StringMapImpl::hash(StringRef Key) { return xxh3_64bits(Key); } +LLVM_ABI uint32_t StringMapImpl::hash(StringRef Key) { + return xxh3_64bits(Key); +} StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) { ItemSize = itemSize; @@ -83,8 +86,8 @@ void StringMapImpl::init(unsigned InitSize) { /// specified bucket will be non-null. Otherwise, it will be null. In either /// case, the FullHashValue field of the bucket will be set to the hash value /// of the string. -unsigned StringMapImpl::LookupBucketFor(StringRef Name, - uint32_t FullHashValue) { +LLVM_ABI unsigned StringMapImpl::LookupBucketFor(StringRef Name, + uint32_t FullHashValue) { #ifdef EXPENSIVE_CHECKS assert(FullHashValue == hash(Name)); #endif @@ -215,7 +218,7 @@ StringMapEntryBase *StringMapImpl::RemoveKey(StringRef Key) { /// RehashTable - Grow the table, redistributing values into the buckets with /// the appropriate mod-of-hashtable-size. -unsigned StringMapImpl::RehashTable(unsigned BucketNo) { +LLVM_ABI unsigned StringMapImpl::RehashTable(unsigned BucketNo) { unsigned NewSize; // If the hash table is now more than 3/4 full, or if fewer than 1/8 of // the buckets are empty (meaning that many are filled with tombstones), diff --git a/llvm/lib/Support/Valgrind.cpp b/llvm/lib/Support/Valgrind.cpp index 5994656c5c031..67ca05410fa4a 100644 --- a/llvm/lib/Support/Valgrind.cpp +++ b/llvm/lib/Support/Valgrind.cpp @@ -12,16 +12,15 @@ // //===----------------------------------------------------------------------===// -#include <stddef.h> #include "llvm/Support/Valgrind.h" #include "llvm/Config/config.h" +#include "llvm/Support/Compiler.h" +#include <stddef.h> #if HAVE_VALGRIND_VALGRIND_H #include <valgrind/valgrind.h> -bool llvm::sys::RunningOnValgrind() { - return RUNNING_ON_VALGRIND; -} +LLVM_ABI bool llvm::sys::RunningOnValgrind() { return RUNNING_ON_VALGRIND; } void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { VALGRIND_DISCARD_TRANSLATIONS(Addr, Len); @@ -29,9 +28,7 @@ void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { #else // !HAVE_VALGRIND_VALGRIND_H -bool llvm::sys::RunningOnValgrind() { - return false; -} +LLVM_ABI bool llvm::sys::RunningOnValgrind() { return false; } void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { } diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index 07b99896543bd..8f9cd413bf758 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -72,7 +72,7 @@ constexpr raw_ostream::Colors raw_ostream::WHITE; constexpr raw_ostream::Colors raw_ostream::SAVEDCOLOR; constexpr raw_ostream::Colors raw_ostream::RESET; -raw_ostream::~raw_ostream() { +LLVM_ABI raw_ostream::~raw_ostream() { // raw_ostream's subclasses should take care to flush the buffer // in their destructors. assert(OutBufCur == OutBufStart && @@ -103,8 +103,8 @@ void raw_ostream::SetBuffered() { SetUnbuffered(); } -void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, - BufferKind Mode) { +LLVM_ABI void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, + BufferKind Mode) { assert(((Mode == BufferKind::Unbuffered && !BufferStart && Size == 0) || (Mode != BufferKind::Unbuffered && BufferStart && Size != 0)) && "stream must be unbuffered or have at least one byte"); @@ -122,7 +122,7 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, assert(OutBufStart <= OutBufEnd && "Invalid size!"); } -raw_ostream &raw_ostream::operator<<(unsigned long N) { +LLVM_ABI raw_ostream &raw_ostream::operator<<(unsigned long N) { write_integer(*this, static_cast<uint64_t>(N), 0, IntegerStyle::Integer); return *this; } @@ -215,7 +215,7 @@ raw_ostream &raw_ostream::operator<<(double N) { return *this; } -void raw_ostream::flush_nonempty() { +LLVM_ABI void raw_ostream::flush_nonempty() { assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty."); size_t Length = OutBufCur - OutBufStart; OutBufCur = OutBufStart; @@ -242,7 +242,7 @@ raw_ostream &raw_ostream::write(unsigned char C) { return *this; } -raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) { +LLVM_ABI raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) { // Group exceptional cases into a single branch. if (LLVM_UNLIKELY(size_t(OutBufEnd - OutBufCur) < Size)) { if (LLVM_UNLIKELY(!OutBufStart)) { @@ -905,7 +905,7 @@ raw_fd_ostream &llvm::outs() { return S; } -raw_fd_ostream &llvm::errs() { +LLVM_ABI raw_fd_ostream &llvm::errs() { // On z/OS we need to enable auto conversion static std::error_code EC = enableAutoConversion(STDERR_FILENO); assert(!EC); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits