@@ -20,6 +20,7 @@ Copyright (c) Intel Corporation (2009-2017).
20
20
#include " options.h"
21
21
22
22
#include " clang/Driver/Options.h"
23
+ #include " llvm/ADT/SmallSet.h"
23
24
#include " llvm/ADT/StringExtras.h"
24
25
#include " llvm/Option/Arg.h"
25
26
#include " llvm/Option/ArgList.h"
@@ -308,11 +309,30 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
308
309
it->second = enabled;
309
310
}
310
311
};
312
+ llvm::SmallSet<llvm::StringRef, 32 > parsedOclCFeatures;
311
313
std::for_each (effectiveArgs.begin (), effectiveArgs.end (),
312
314
[&](const ArgsVector::value_type &a) {
313
315
if (a.find (" -cl-ext=" ) == 0 )
314
316
parseClExt (a);
317
+ else if (a.find (" -D__opencl_c_" ) == 0 )
318
+ parsedOclCFeatures.insert (a);
315
319
});
320
+
321
+ // "opencl-c-base.h" unconditionally enables a list of so-called "optional
322
+ // core" language features. We need to undef those that aren't explicitly
323
+ // defined within the compilation command (which would suggest that the
324
+ // target platform supports the corresponding feature).
325
+ const char * optionalCoreOclCFeaturesList[] = {
326
+ " __opencl_c_work_group_collective_functions" ,
327
+ " __opencl_c_atomic_order_seq_cst" ,
328
+ " __opencl_c_atomic_scope_device" ,
329
+ " __opencl_c_atomic_scope_all_devices" ,
330
+ " __opencl_c_read_write_images" };
331
+ for (std::string OclCFeature : optionalCoreOclCFeaturesList) {
332
+ if (!parsedOclCFeatures.contains (std::string (" -D" ) + OclCFeature))
333
+ effectiveArgs.push_back (std::string (" -D__undef_" ) + OclCFeature);
334
+ }
335
+
316
336
// extension is enabled in PCH but disabled or not specifed in options =>
317
337
// disable pch
318
338
bool useModules =
0 commit comments