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