erik2020 created this revision. erik2020 added a reviewer: ldrumm. erik2020 added a project: clang. Herald added subscribers: cfe-commits, dexonsmith, Anastasia, yaxunl. erik2020 requested review of this revision.
Calling any of the `OpenCLOptions::is*()` functions (except `isKnown()`) with an unknown extension string results in a seg fault. This patch adds assertions to catch these conditions. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D90928 Files: clang/include/clang/Basic/OpenCLOptions.h Index: clang/include/clang/Basic/OpenCLOptions.h =================================================================== --- clang/include/clang/Basic/OpenCLOptions.h +++ clang/include/clang/Basic/OpenCLOptions.h @@ -37,12 +37,14 @@ } bool isEnabled(llvm::StringRef Ext) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); return OptMap.find(Ext)->second.Enabled; } // Is supported as either an extension or an (optional) core feature for // OpenCL version \p CLVer. bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); // In C++ mode all extensions should work at least as in v2.0. auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; auto I = OptMap.find(Ext)->getValue(); @@ -52,6 +54,7 @@ // Is supported (optional) OpenCL core features for OpenCL version \p CLVer. // For supported extension, return false. bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); // In C++ mode all extensions should work at least as in v2.0. auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; auto I = OptMap.find(Ext)->getValue(); @@ -61,6 +64,7 @@ // Is supported OpenCL extension for OpenCL version \p CLVer. // For supported (optional) core feature, return false. bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); // In C++ mode all extensions should work at least as in v2.0. auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; auto I = OptMap.find(Ext)->getValue();
Index: clang/include/clang/Basic/OpenCLOptions.h =================================================================== --- clang/include/clang/Basic/OpenCLOptions.h +++ clang/include/clang/Basic/OpenCLOptions.h @@ -37,12 +37,14 @@ } bool isEnabled(llvm::StringRef Ext) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); return OptMap.find(Ext)->second.Enabled; } // Is supported as either an extension or an (optional) core feature for // OpenCL version \p CLVer. bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); // In C++ mode all extensions should work at least as in v2.0. auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; auto I = OptMap.find(Ext)->getValue(); @@ -52,6 +54,7 @@ // Is supported (optional) OpenCL core features for OpenCL version \p CLVer. // For supported extension, return false. bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); // In C++ mode all extensions should work at least as in v2.0. auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; auto I = OptMap.find(Ext)->getValue(); @@ -61,6 +64,7 @@ // Is supported OpenCL extension for OpenCL version \p CLVer. // For supported (optional) core feature, return false. bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const { + assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension."); // In C++ mode all extensions should work at least as in v2.0. auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; auto I = OptMap.find(Ext)->getValue();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits