[PATCH] D102067: [amdgpu-arch] Guard hsa.h with __has_include
Jon Chesterfield via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 7 06:12:05 PDT 2021
JonChesterfield added a comment.
Logic doesn't look quite right to me. If the compiler supports has_include, but neither of those headers exist, we fall through to main() which won't compile.
How about:
#if defined(__has_include)
#if __has_include("hsa.h")
#define HSA_FOUND 1 // name tbd
#include "hsa.h"
#elif __has_include("hsa/hsa.h")
#define HSA_FOUND 1
#include "hsa/hsa.h"
#else
#define HSA_FOUND 0
#endif
#else
#define HSA_FOUND 0
#endif
#if !HSA_FOUND
int main() { return 1; }
#else
// all the current stuff
#endif
That takes the approach that missing __has_include is a bad sign and immediately gives up. As far as I can tell it was introduced ~ 10 years ago, and was more recently added to c++17 (https://en.cppreference.com/w/cpp/preprocessor/include, which uses a similar pattern to the above in terms of booleans). Seems to be present in gcc, clang, msvc and we have a safe fallback if it isn't.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102067/new/
https://reviews.llvm.org/D102067
More information about the cfe-commits
mailing list