Skip to content

Commit a7a0208

Browse files
authored
[flang] Assert the Options fit into the storage bits (#126169)
1 parent 26fc2e9 commit a7a0208

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

flang/include/flang/Support/LangOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ class LangOptions : public LangOptionsBase {
6262
#define LANGOPT(Name, Bits, Default)
6363
#define ENUM_LANGOPT(Name, Type, Bits, Default) \
6464
Type get##Name() const { return static_cast<Type>(Name); } \
65-
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
65+
void set##Name(Type Value) { \
66+
assert(static_cast<unsigned>(Value) < (1u << Bits)); \
67+
Name = static_cast<unsigned>(Value); \
68+
}
6669
#include "LangOptions.def"
6770

6871
/// Name of the IR file that contains the result of the OpenMP target

0 commit comments

Comments
 (0)