@@ -20,6 +20,7 @@ Copyright (c) Intel Corporation (2009-2017).
2020#include " options.h"
2121
2222#include " clang/Driver/Options.h"
23+ #include " llvm/ADT/SmallSet.h"
2324#include " llvm/ADT/StringExtras.h"
2425#include " llvm/Option/Arg.h"
2526#include " llvm/Option/ArgList.h"
@@ -308,11 +309,30 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
308309 it->second = enabled;
309310 }
310311 };
312+ llvm::SmallSet<llvm::StringRef, 32 > parsedOclCFeatures;
311313 std::for_each (effectiveArgs.begin (), effectiveArgs.end (),
312314 [&](const ArgsVector::value_type &a) {
313315 if (a.find (" -cl-ext=" ) == 0 )
314316 parseClExt (a);
317+ else if (a.find (" -D__opencl_c_" ) == 0 )
318+ parsedOclCFeatures.insert (a);
315319 });
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+
316336 // extension is enabled in PCH but disabled or not specifed in options =>
317337 // disable pch
318338 bool useModules =
0 commit comments