diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/OrcV2CBindingsLazy.c b/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/OrcV2CBindingsLazy.c --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/OrcV2CBindingsLazy.c +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/OrcV2CBindingsLazy.c @@ -195,7 +195,7 @@ LLVMOrcJITDylibRef MainJD = LLVMOrcLLJITGetMainJITDylib(J); LLVMOrcMaterializationUnitRef MU = LLVMOrcLazyReexports(LCTM, ISM, MainJD, ReExports, 2); - LLVMOrcJITDylibDefine(MainJD, MU); + (void)LLVMOrcJITDylibDefine(MainJD, MU); } // Look up the address of our demo entry point. diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/OrcV2CBindingsVeryLazy.c b/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/OrcV2CBindingsVeryLazy.c --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/OrcV2CBindingsVeryLazy.c +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/OrcV2CBindingsVeryLazy.c @@ -220,8 +220,8 @@ &Materialize, NULL, &Destroy); LLVMOrcJITDylibRef MainJD = LLVMOrcLLJITGetMainJITDylib(J); - LLVMOrcJITDylibDefine(MainJD, FooMU); - LLVMOrcJITDylibDefine(MainJD, BarMU); + (void)LLVMOrcJITDylibDefine(MainJD, FooMU); + (void)LLVMOrcJITDylibDefine(MainJD, BarMU); } // add lazy reexports @@ -251,7 +251,7 @@ LLVMOrcJITDylibRef MainJD = LLVMOrcLLJITGetMainJITDylib(J); LLVMOrcMaterializationUnitRef MU = LLVMOrcLazyReexports(LCTM, ISM, MainJD, ReExports, 2); - LLVMOrcJITDylibDefine(MainJD, MU); + (void)LLVMOrcJITDylibDefine(MainJD, MU); } // Look up the address of our demo entry point. diff --git a/llvm/include/llvm-c/Error.h b/llvm/include/llvm-c/Error.h --- a/llvm/include/llvm-c/Error.h +++ b/llvm/include/llvm-c/Error.h @@ -30,7 +30,7 @@ /** * Opaque reference to an error instance. Null serves as the 'success' value. */ -typedef struct LLVMOpaqueError *LLVMErrorRef; +LLVM_NODISCARD_GNU_STYLE_CLANG typedef struct LLVMOpaqueError *LLVMErrorRef; /** * Error type identifier. diff --git a/llvm/include/llvm-c/ExternC.h b/llvm/include/llvm-c/ExternC.h --- a/llvm/include/llvm-c/ExternC.h +++ b/llvm/include/llvm-c/ExternC.h @@ -36,4 +36,18 @@ #define LLVM_C_EXTERN_C_END LLVM_C_STRICT_PROTOTYPES_END #endif +#ifndef LLVM_HAS_ATTRIBUTE +#if defined(__has_attribute) +#define LLVM_HAS_ATTRIBUTE(x) __has_attribute(x) +#else +#define LLVM_HAS_ATTRIBUTE(x) 0 +#endif +#endif + +#if LLVM_HAS_ATTRIBUTE(warn_unused_result) && defined(__clang__) +#define LLVM_NODISCARD_GNU_STYLE_CLANG __attribute__((warn_unused_result)) +#else +#define LLVM_NODISCARD_GNU_STYLE_CLANG +#endif + #endif diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp --- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp @@ -84,7 +84,7 @@ return; } - LLVMOrcDisposeLLJIT(J); + (void)LLVMOrcDisposeLLJIT(J); TargetSupported = true; } @@ -110,7 +110,7 @@ // Check whether Jit has already been torn down -- we allow clients to do // this manually to check teardown behavior. if (Jit) { - LLVMOrcDisposeLLJIT(Jit); + (void)LLVMOrcDisposeLLJIT(Jit); Jit = nullptr; } } @@ -441,7 +441,7 @@ FAIL() << "Symbol \"sum\" was not added into JIT (triple = " << TargetTriple << "): " << toString(E); ASSERT_TRUE(!!TestFnAddr); - LLVMOrcResourceTrackerRemove(RT); + (void)LLVMOrcResourceTrackerRemove(RT); LLVMOrcJITTargetAddress OutAddr; LLVMErrorRef Err = LLVMOrcLLJITLookup(Jit, &OutAddr, "sum"); ASSERT_TRUE(Err); @@ -576,7 +576,7 @@ {OtherSymbol, Flags}, {DependencySymbol, Flags}, }; - LLVMOrcMaterializationResponsibilityDefineMaterializing(MR, NewSymbols, 2); + (void)LLVMOrcMaterializationResponsibilityDefineMaterializing(MR, NewSymbols, 2); LLVMOrcRetainSymbolStringPoolEntry(OtherSymbol); LLVMOrcMaterializationResponsibilityRef OtherMR = NULL; @@ -636,13 +636,13 @@ // See FIXME above LLVMOrcCSymbolMapPair Pair = {DependencySymbol, Sym}; - LLVMOrcMaterializationResponsibilityNotifyResolved(MR, &Pair, 1); + (void)LLVMOrcMaterializationResponsibilityNotifyResolved(MR, &Pair, 1); // DependencySymbol no longer owned by us Pair = {TargetSym.Name, Sym}; - LLVMOrcMaterializationResponsibilityNotifyResolved(MR, &Pair, 1); + (void)LLVMOrcMaterializationResponsibilityNotifyResolved(MR, &Pair, 1); - LLVMOrcMaterializationResponsibilityNotifyEmitted(MR); + (void)LLVMOrcMaterializationResponsibilityNotifyEmitted(MR); LLVMOrcDisposeMaterializationResponsibility(MR); } @@ -655,7 +655,7 @@ LLVMOrcMaterializationUnitRef MU = LLVMOrcCreateCustomMaterializationUnit( "MU", (void *)Jit, &Sym, 1, NULL, &Materialize, NULL, &Destroy); LLVMOrcJITDylibRef JD = LLVMOrcLLJITGetMainJITDylib(Jit); - LLVMOrcJITDylibDefine(JD, MU); + (void)LLVMOrcJITDylibDefine(JD, MU); LLVMOrcJITTargetAddress Addr; if (LLVMErrorRef Err = LLVMOrcLLJITLookup(Jit, &Addr, "foo")) { @@ -777,7 +777,7 @@ LLVMOrcReleaseSymbolStringPoolEntry(Ctx.NameToGenerate); // Explicitly tear down the JIT. - LLVMOrcDisposeLLJIT(Jit); + (void)LLVMOrcDisposeLLJIT(Jit); Jit = nullptr; // Check that the generator context was "destroyed".