https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/195540

>From 61469343267f723443ebdd6436336da8c3c4b1ac Mon Sep 17 00:00:00 2001
From: Caroline Tice <[email protected]>
Date: Sun, 3 May 2026 11:33:56 -0700
Subject: [PATCH 1/2] [LLDB] Fix UBSan issue with ValueType enums.

ValueTypeSyntheticMask, when bitwise OR'd with ValueType enums,
produces a value that is outside the official enum range for ValueTypes.
This causes UBSan errors, when UBSan is set to check enum values.
E.g. If you build LLDB with the Cmake flags

-DCMAKE_CXX_FLAGS="-fsanitize=enum -fsanitize-trap=enum"
-DCMAKE_C_FLAGS="-fsanitize=enum -fsanitize-trap=enum"

Then try to run the LLDB test TestScripedFrameProvider, it crashes
with a SIGILL from UBSan.

This change fixes that by pulling ValueTypeSyntheticMask into the
ValueType enums, expanding the valid enum range and making the
bitwise OR'd values valid.
---
 lldb/include/lldb/Utility/ValueType.h       |  6 +++---
 lldb/include/lldb/lldb-enumerations.h       | 11 +++++------
 lldb/source/Commands/CommandObjectFrame.cpp |  1 +
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lldb/include/lldb/Utility/ValueType.h 
b/lldb/include/lldb/Utility/ValueType.h
index 307be07a3fc81..a547c28ae7ccb 100644
--- a/lldb/include/lldb/Utility/ValueType.h
+++ b/lldb/include/lldb/Utility/ValueType.h
@@ -15,17 +15,17 @@ namespace lldb_private {
 /// Get the base value type - for when we don't care if the value is synthetic
 /// or not, or when we've already handled that case.
 constexpr lldb::ValueType GetBaseValueType(lldb::ValueType vt) {
-  return lldb::ValueType(vt & ~lldb::ValueTypeSyntheticMask);
+  return lldb::ValueType(vt & ~lldb::ValueType::eValueTypeSyntheticMask);
 }
 
 /// Given a base value type, return a version that carries the synthetic bit.
 constexpr lldb::ValueType GetSyntheticValueType(lldb::ValueType base) {
-  return lldb::ValueType(base | lldb::ValueTypeSyntheticMask);
+  return lldb::ValueType(base | lldb::ValueType::eValueTypeSyntheticMask);
 }
 
 /// Return true if vt represents a synthetic value, false if not.
 constexpr bool IsSyntheticValueType(lldb::ValueType vt) {
-  return vt & lldb::ValueTypeSyntheticMask;
+  return vt & lldb::ValueType::eValueTypeSyntheticMask;
 }
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 9b21af2e9882e..dbb167344b042 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -342,14 +342,13 @@ enum ValueType {
   eValueTypeVariableThreadLocal = 8, ///< thread local storage variable
   eValueTypeVTable = 9,              ///< virtual function table
   eValueTypeVTableEntry = 10, ///< function pointer in virtual function table
+  /// A mask that we can use to check if the value type is synthetic or not.
+  // NOTE: This limits the number of value types to 31, but that's 3x more than
+  // what we currently have now. See lldb/Utility/ValueType.h for helpers for
+  // working with synthetic value types.
+  eValueTypeSyntheticMask = 0x20,
 };
 
-/// A mask that we can use to check if the value type is synthetic or not.
-// NOTE: This limits the number of value types to 31, but that's 3x more than
-// what we currently have now. See lldb/Utility/ValueType.h for helpers for
-// working with synthetic value types.
-static constexpr unsigned ValueTypeSyntheticMask = 0x20;
-
 /// Token size/granularities for Input Readers.
 
 enum InputReaderGranularity {
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp 
b/lldb/source/Commands/CommandObjectFrame.cpp
index b1cc6c42a04fc..e40a80ad6ff07 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -562,6 +562,7 @@ may even involve JITing and running code in the target 
program.)");
     case eValueTypeVariableThreadLocal:
     case eValueTypeVTable:
     case eValueTypeVTableEntry:
+    case eValueTypeSyntheticMask:
       // The default for all other value types is is_synthetic. Aside from the
       // modifiers above that should apply equally to synthetic and normal
       // variables, any other synthetic variable we should default to showing.

>From 07a9d2da7a49ca8a366b50187d28d979b076b88b Mon Sep 17 00:00:00 2001
From: Caroline Tice <[email protected]>
Date: Tue, 5 May 2026 09:09:28 -0700
Subject: [PATCH 2/2] Implement alternative fix: Give a fixed underlying type
 to the enum.

---
 lldb/include/lldb/Utility/ValueType.h       |  6 +++---
 lldb/include/lldb/lldb-enumerations.h       | 13 +++++++------
 lldb/source/Commands/CommandObjectFrame.cpp |  1 -
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Utility/ValueType.h 
b/lldb/include/lldb/Utility/ValueType.h
index a547c28ae7ccb..307be07a3fc81 100644
--- a/lldb/include/lldb/Utility/ValueType.h
+++ b/lldb/include/lldb/Utility/ValueType.h
@@ -15,17 +15,17 @@ namespace lldb_private {
 /// Get the base value type - for when we don't care if the value is synthetic
 /// or not, or when we've already handled that case.
 constexpr lldb::ValueType GetBaseValueType(lldb::ValueType vt) {
-  return lldb::ValueType(vt & ~lldb::ValueType::eValueTypeSyntheticMask);
+  return lldb::ValueType(vt & ~lldb::ValueTypeSyntheticMask);
 }
 
 /// Given a base value type, return a version that carries the synthetic bit.
 constexpr lldb::ValueType GetSyntheticValueType(lldb::ValueType base) {
-  return lldb::ValueType(base | lldb::ValueType::eValueTypeSyntheticMask);
+  return lldb::ValueType(base | lldb::ValueTypeSyntheticMask);
 }
 
 /// Return true if vt represents a synthetic value, false if not.
 constexpr bool IsSyntheticValueType(lldb::ValueType vt) {
-  return vt & lldb::ValueType::eValueTypeSyntheticMask;
+  return vt & lldb::ValueTypeSyntheticMask;
 }
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index dbb167344b042..cd5d58971e7e3 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -330,7 +330,7 @@ enum ErrorType {
   eErrorTypeWin32       ///< Standard Win32 error codes.
 };
 
-enum ValueType {
+enum ValueType : uint32_t {
   eValueTypeInvalid = 0,
   eValueTypeVariableGlobal = 1,   ///< globals variable
   eValueTypeVariableStatic = 2,   ///< static variable
@@ -342,13 +342,14 @@ enum ValueType {
   eValueTypeVariableThreadLocal = 8, ///< thread local storage variable
   eValueTypeVTable = 9,              ///< virtual function table
   eValueTypeVTableEntry = 10, ///< function pointer in virtual function table
-  /// A mask that we can use to check if the value type is synthetic or not.
-  // NOTE: This limits the number of value types to 31, but that's 3x more than
-  // what we currently have now. See lldb/Utility/ValueType.h for helpers for
-  // working with synthetic value types.
-  eValueTypeSyntheticMask = 0x20,
 };
 
+/// A mask that we can use to check if the value type is synthetic or not.
+// NOTE: This limits the number of value types to 31, but that's 3x more than
+// what we currently have now. See lldb/Utility/ValueType.h for helpers for
+// working with synthetic value types.
+static constexpr unsigned ValueTypeSyntheticMask = 0x20;
+
 /// Token size/granularities for Input Readers.
 
 enum InputReaderGranularity {
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp 
b/lldb/source/Commands/CommandObjectFrame.cpp
index e40a80ad6ff07..b1cc6c42a04fc 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -562,7 +562,6 @@ may even involve JITing and running code in the target 
program.)");
     case eValueTypeVariableThreadLocal:
     case eValueTypeVTable:
     case eValueTypeVTableEntry:
-    case eValueTypeSyntheticMask:
       // The default for all other value types is is_synthetic. Aside from the
       // modifiers above that should apply equally to synthetic and normal
       // variables, any other synthetic variable we should default to showing.

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to