[flang-commits] [flang] a7a0208 - [flang] Assert the Options fit into the storage bits (#126169)

via flang-commits flang-commits at lists.llvm.org
Sun Feb 16 15:04:02 PST 2025


Author: Florian Mayer
Date: 2025-02-16T15:03:59-08:00
New Revision: a7a02083acf39b9f1ad7edec3b7e344afc6cac49

URL: https://github.com/llvm/llvm-project/commit/a7a02083acf39b9f1ad7edec3b7e344afc6cac49
DIFF: https://github.com/llvm/llvm-project/commit/a7a02083acf39b9f1ad7edec3b7e344afc6cac49.diff

LOG: [flang] Assert the Options fit into the storage bits (#126169)

Added: 
    

Modified: 
    flang/include/flang/Support/LangOptions.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Support/LangOptions.h b/flang/include/flang/Support/LangOptions.h
index fac6fb92df85a..1dd676e62a9e5 100644
--- a/flang/include/flang/Support/LangOptions.h
+++ b/flang/include/flang/Support/LangOptions.h
@@ -62,7 +62,10 @@ class LangOptions : public LangOptionsBase {
 #define LANGOPT(Name, Bits, Default)
 #define ENUM_LANGOPT(Name, Type, Bits, Default) \
   Type get##Name() const { return static_cast<Type>(Name); } \
-  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
+  void set##Name(Type Value) { \
+    assert(static_cast<unsigned>(Value) < (1u << Bits)); \
+    Name = static_cast<unsigned>(Value); \
+  }
 #include "LangOptions.def"
 
   /// Name of the IR file that contains the result of the OpenMP target


        


More information about the flang-commits mailing list