[PATCH] D51501: [CUDA] Fix CUDA compilation broken by D50845

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 30 12:04:22 PDT 2018


tra created this revision.
tra added a reviewer: Hahnfeld.
Herald added subscribers: bixia, jlebar, sanjoy.

This keeps predefined macros for CUDA to work as they were before and lets OpenMP control the set of macros it needs.


https://reviews.llvm.org/D51501

Files:
  clang/lib/Frontend/InitPreprocessor.cpp


Index: clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -1158,8 +1158,16 @@
 
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
   if (InitOpts.UsePredefines) {
+    // CUDA and OpenMP handle preprocessing differently.  CUDA wants to see
+    // identical preprocessed output (as close to it as possible), so it
+    // provides full set of predefined macros for both sides of compilation.
+    if (LangOpts.CUDA && PP.getAuxTargetInfo())
+      InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
+                                 Builder);
     InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder);
-    if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo())
+    // OpenMP relies on selectively picking predefined macros to work around the
+    // bits of host includes it can't compile during device-side compilation.
+    if (LangOpts.OpenMPIsDevice && PP.getAuxTargetInfo())
       InitializePredefinedAuxMacros(*PP.getAuxTargetInfo(), LangOpts, Builder);
 
     // Install definitions to make Objective-C++ ARC work well with various


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51501.163388.patch
Type: text/x-patch
Size: 1272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180830/0592a068/attachment.bin>


More information about the cfe-commits mailing list