[llvm] Add __attribute__((warn_unused_result)) to LLVMErrorRef (PR #87025)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 13:33:11 PDT 2024


================
@@ -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__)
----------------
dwblaikie wrote:

> Do we still need to do this? 

I think the original rationale still applies - [we support building LLVM with Clang 5.0](https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library) and support for `__attribute__((warn_unused_result))` was added in Clang 15. Prior to that clang warns that the attribute is used out of place - so we'd want to conditionalize the attribute so as not to warn/werror-break the build when using a supported (>= 5) clang < 15.

>  We don't have a macro for version checking Clang in Compiler.h, but we probably could use one. We have LLVM_GNUC_PREREQ and LLVM_MSC_PREREQ, so adding LLVM_CLANG_PREREQ would be pretty natural.

Fair - though this one can't go in Compiler.h because it needs to be down in llvm-c and I don't think Compiler.h is that low-level. So we might have to pull the other _PREREQ macros down into llvm-c for symmetry.

https://github.com/llvm/llvm-project/pull/87025


More information about the llvm-commits mailing list