@@ -1077,33 +1077,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
1077
1077
if (JA.isOffloading (Action::OFK_HIP))
1078
1078
getToolChain ().AddHIPIncludeArgs (Args, CmdArgs);
1079
1079
1080
- // If we are compiling for a GPU target we want to override the system headers
1081
- // with ones created by the 'libc' project if present.
1082
- if (!Args.hasArg (options::OPT_nostdinc) &&
1083
- !Args.hasArg (options::OPT_nogpuinc) &&
1084
- !Args.hasArg (options::OPT_nobuiltininc)) {
1085
- // Without an offloading language we will include these headers directly.
1086
- // Offloading languages will instead only use the declarations stored in
1087
- // the resource directory at clang/lib/Headers/llvm_libc_wrappers.
1088
- if ((getToolChain ().getTriple ().isNVPTX () ||
1089
- getToolChain ().getTriple ().isAMDGCN ()) &&
1090
- C.getActiveOffloadKinds () == Action::OFK_None) {
1091
- SmallString<128 > P (llvm::sys::path::parent_path (D.Dir ));
1092
- llvm::sys::path::append (P, " include" );
1093
- llvm::sys::path::append (P, getToolChain ().getTripleString ());
1094
- CmdArgs.push_back (" -internal-isystem" );
1095
- CmdArgs.push_back (Args.MakeArgString (P));
1096
- } else if (C.getActiveOffloadKinds () == Action::OFK_OpenMP) {
1097
- // TODO: CUDA / HIP include their own headers for some common functions
1098
- // implemented here. We'll need to clean those up so they do not conflict.
1099
- SmallString<128 > P (D.ResourceDir );
1100
- llvm::sys::path::append (P, " include" );
1101
- llvm::sys::path::append (P, " llvm_libc_wrappers" );
1102
- CmdArgs.push_back (" -internal-isystem" );
1103
- CmdArgs.push_back (Args.MakeArgString (P));
1104
- }
1105
- }
1106
-
1107
1080
// If we are offloading to a target via OpenMP we need to include the
1108
1081
// openmp_wrappers folder which contains alternative system headers.
1109
1082
if (JA.isDeviceOffloading (Action::OFK_OpenMP) &&
@@ -1276,6 +1249,35 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
1276
1249
});
1277
1250
}
1278
1251
1252
+ // If we are compiling for a GPU target we want to override the system headers
1253
+ // with ones created by the 'libc' project if present.
1254
+ // TODO: This should be moved to `AddClangSystemIncludeArgs` by passing the
1255
+ // OffloadKind as an argument.
1256
+ if (!Args.hasArg (options::OPT_nostdinc) &&
1257
+ !Args.hasArg (options::OPT_nogpuinc) &&
1258
+ !Args.hasArg (options::OPT_nobuiltininc)) {
1259
+ // Without an offloading language we will include these headers directly.
1260
+ // Offloading languages will instead only use the declarations stored in
1261
+ // the resource directory at clang/lib/Headers/llvm_libc_wrappers.
1262
+ if ((getToolChain ().getTriple ().isNVPTX () ||
1263
+ getToolChain ().getTriple ().isAMDGCN ()) &&
1264
+ C.getActiveOffloadKinds () == Action::OFK_None) {
1265
+ SmallString<128 > P (llvm::sys::path::parent_path (D.Dir ));
1266
+ llvm::sys::path::append (P, " include" );
1267
+ llvm::sys::path::append (P, getToolChain ().getTripleString ());
1268
+ CmdArgs.push_back (" -internal-isystem" );
1269
+ CmdArgs.push_back (Args.MakeArgString (P));
1270
+ } else if (C.getActiveOffloadKinds () == Action::OFK_OpenMP) {
1271
+ // TODO: CUDA / HIP include their own headers for some common functions
1272
+ // implemented here. We'll need to clean those up so they do not conflict.
1273
+ SmallString<128 > P (D.ResourceDir );
1274
+ llvm::sys::path::append (P, " include" );
1275
+ llvm::sys::path::append (P, " llvm_libc_wrappers" );
1276
+ CmdArgs.push_back (" -internal-isystem" );
1277
+ CmdArgs.push_back (Args.MakeArgString (P));
1278
+ }
1279
+ }
1280
+
1279
1281
// Add system include arguments for all targets but IAMCU.
1280
1282
if (!IsIAMCU)
1281
1283
forAllAssociatedToolChains (C, JA, getToolChain (),
0 commit comments