From a7a02083acf39b9f1ad7edec3b7e344afc6cac49 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Sun, 16 Feb 2025 15:03:59 -0800 Subject: [PATCH] [flang] Assert the Options fit into the storage bits (#126169) --- flang/include/flang/Support/LangOptions.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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(Name); } \ - void set##Name(Type Value) { Name = static_cast(Value); } + void set##Name(Type Value) { \ + assert(static_cast(Value) < (1u << Bits)); \ + Name = static_cast(Value); \ + } #include "LangOptions.def" /// Name of the IR file that contains the result of the OpenMP target