@@ -648,9 +648,12 @@ class LangOptions : public LangOptionsBase {
648648
649649 // Define accessors/mutators for language options of enumeration type.
650650#define LANGOPT (Name, Bits, Default, Description )
651- #define ENUM_LANGOPT (Name, Type, Bits, Default, Description ) \
652- Type get##Name() const { return static_cast <Type>(Name); } \
653- void set##Name(Type Value) { Name = static_cast <unsigned >(Value); }
651+ #define ENUM_LANGOPT (Name, Type, Bits, Default, Description ) \
652+ Type get##Name() const { return static_cast <Type>(Name); } \
653+ void set##Name(Type Value) { \
654+ assert (static_cast <unsigned >(Value) < (1u << Bits)); \
655+ Name = static_cast <unsigned >(Value); \
656+ }
654657#include " clang/Basic/LangOptions.def"
655658
656659 // / Are we compiling a module?
@@ -959,11 +962,14 @@ class FPOptions {
959962 void applyChanges (FPOptionsOverride FPO);
960963
961964 // We can define most of the accessors automatically:
965+ // TODO: consider enforcing the assertion that value fits within bits
966+ // statically.
962967#define OPTION (NAME, TYPE, WIDTH, PREVIOUS ) \
963968 TYPE get##NAME() const { \
964969 return static_cast <TYPE>((Value & NAME##Mask) >> NAME##Shift); \
965970 } \
966971 void set##NAME(TYPE value) { \
972+ assert (storage_type (value) < (1u << WIDTH)); \
967973 Value = (Value & ~NAME##Mask) | (storage_type (value) << NAME##Shift); \
968974 }
969975#include " clang/Basic/FPOptions.def"
0 commit comments