From 6e52c89eefc5400f824e3708cad3c6bddb0c4afa Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Fri, 18 Nov 2016 00:41:27 +0000 Subject: [PATCH] [CUDA] Initialize our header search using the host triple. Summary: This used to work because system headers are found in a (somewhat) predictable set of locations on Linux. But this is not the case on MacOS; without this change, we don't look in the right places for our headers when doing device-side compilation on Mac. Reviewers: tra Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26776 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287286 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInstance.cpp | 11 +++++++++-- test/Preprocessor/cuda-macos-includes.cu | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/Preprocessor/cuda-macos-includes.cu diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index b96dc70cf5..6fb880f786 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -334,9 +334,16 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), getFrontendOpts()); - // Initialize the header search object. + // Initialize the header search object. In CUDA compilations, we use the aux + // triple (the host triple) to initialize our header search, since we need to + // find the host headers in order to compile the CUDA code. + const llvm::Triple *HeaderSearchTriple = &PP->getTargetInfo().getTriple(); + if (PP->getTargetInfo().getTriple().getOS() == llvm::Triple::CUDA && + PP->getAuxTargetInfo()) + HeaderSearchTriple = &PP->getAuxTargetInfo()->getTriple(); + ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(), getHeaderSearchOpts(), - PP->getLangOpts(), PP->getTargetInfo().getTriple()); + PP->getLangOpts(), *HeaderSearchTriple); PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP); diff --git a/test/Preprocessor/cuda-macos-includes.cu b/test/Preprocessor/cuda-macos-includes.cu new file mode 100644 index 0000000000..da9f393186 --- /dev/null +++ b/test/Preprocessor/cuda-macos-includes.cu @@ -0,0 +1,13 @@ +// RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \ +// RUN: -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \ +// RUN: -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s + +// RUN: %clang -cc1 -isysroot /var/empty \ +// RUN: -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \ +// RUN: -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s + +// Check that when we do CUDA host and device compiles on MacOS, we check for +// includes in /System/Library/Frameworks and /Library/Frameworks. + +// CHECK-DAG: ignoring nonexistent directory "/var/empty/System/Library/Frameworks" +// CHECK-DAG: ignoring nonexistent directory "/var/empty/Library/Frameworks" -- 2.40.0