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

Florian Mayer via flang-commits flang-commits at lists.llvm.org
Thu Feb 6 18:14:22 PST 2025


https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/126169

None

>From b010eb24d147455d57e13c39a480f28b8886a565 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Thu, 6 Feb 2025 18:14:09 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 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 fac6fb92df85a25..1dd676e62a9e57f 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