Index: include/clang/Basic/OpenCLOptions.h =================================================================== --- include/clang/Basic/OpenCLOptions.h +++ include/clang/Basic/OpenCLOptions.h @@ -57,13 +57,35 @@ // Is supported OpenCL extension for OpenCL version \p CLVer. // For supported (optional) core feature, return false. - bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const { + bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const { auto I = OptMap.find(Ext)->getValue(); return I.Supported && I.Avail <= CLVer && (I.Core == ~0U || CLVer < I.Core); } + llvm::StringRef split(llvm::StringRef Ext, bool& V) { + switch (Ext[0]) { + case '+': + V = true; + Ext = Ext.drop_front(); + break; + case '-': + V = false; + Ext = Ext.drop_front(); + break; + } + return Ext; + } + void enable(llvm::StringRef Ext, bool V = true) { + assert(!Ext.empty() && "Extension is empty."); + + Ext = split(Ext, V); + + if (Ext.equals("all")) { + enableAll(V); + return; + } OptMap[Ext].Enabled = V; } @@ -74,16 +96,7 @@ void support(llvm::StringRef Ext, bool V = true) { assert(!Ext.empty() && "Extension is empty."); - switch (Ext[0]) { - case '+': - V = true; - Ext = Ext.drop_front(); - break; - case '-': - V = false; - Ext = Ext.drop_front(); - break; - } + Ext = split(Ext, V); if (Ext.equals("all")) { supportAll(V); @@ -116,10 +129,14 @@ I->second.Supported = On; } - void disableAll() { + void enableAll(bool On = true) { for (llvm::StringMap::iterator I = OptMap.begin(), E = OptMap.end(); I != E; ++I) - I->second.Enabled = false; + I->second.Enabled = On; + } + + void disableAll() { + enableAll(false); } void enableSupportedCore(unsigned CLVer) { Index: lib/Serialization/ASTReader.cpp =================================================================== --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -7525,6 +7525,13 @@ SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap; SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap; + // OpenCL features imported from a module can be overwritten by -cl-ext option + for (const auto &Ext : + getContext().getTargetInfo().getTargetOpts().OpenCLExtensionsAsWritten) { + SemaObj->OpenCLFeatures.support(Ext); + SemaObj->OpenCLFeatures.enable(Ext); + } + UpdateSema(); }