[clang] [clang-repl] Fix unboxing of va_args Value on 32-bit ARM (#94994) (PR #96900)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 05:34:08 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Stefan Gränitz (weliveindetail)

<details>
<summary>Changes</summary>

todo

---
Full diff: https://github.com/llvm/llvm-project/pull/96900.diff


3 Files Affected:

- (modified) clang/include/clang/Interpreter/Value.h (+2) 
- (modified) clang/lib/Interpreter/Interpreter.cpp (+30-1) 
- (modified) clang/unittests/Interpreter/InterpreterTest.cpp (-2) 


``````````diff
diff --git a/clang/include/clang/Interpreter/Value.h b/clang/include/clang/Interpreter/Value.h
index d70e8f8719026..f1dcae2d672c0 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -98,6 +98,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
     void *m_Ptr;
   };
 
+  static_assert(sizeof(Storage) <= 2 * sizeof(void *), "va_args");
+
 public:
   enum Kind {
 #define X(type, name) K_##name,
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 7a95278914276..11f3273dff45f 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -877,7 +877,36 @@ extern "C" void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc(
   } else {
     if (const auto *ET = QT->getAs<EnumType>())
       QT = ET->getDecl()->getIntegerType();
-    switch (QT->castAs<BuiltinType>()->getKind()) {
+
+    BuiltinType::Kind K = QT->castAs<BuiltinType>()->getKind();
+  #ifdef __arm__
+    switch (K) {
+    default:
+      llvm_unreachable("unknown type kind!");
+    case BuiltinType::Bool:
+    case BuiltinType::SChar:
+    case BuiltinType::Char_S:
+    case BuiltinType::Char_U:
+    case BuiltinType::UChar:
+    case BuiltinType::Short:
+    case BuiltinType::UShort:
+    case BuiltinType::Int:
+    case BuiltinType::UInt:
+    case BuiltinType::Long:
+    case BuiltinType::ULong:
+    case BuiltinType::LongLong:
+    case BuiltinType::ULongLong:
+    case BuiltinType::Float:
+    case BuiltinType::Double:
+      // Consume unused leading 32-bit of storage
+      va_arg(args, int);
+
+    case BuiltinType::LongDouble:
+      break;
+    }
+  #endif
+
+    switch (K) {
     default:
       llvm_unreachable("unknown type kind!");
       break;
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index bbd854149d5f5..37978b09adad2 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -284,7 +284,6 @@ TEST_F(InterpreterTest, InstantiateTemplate) {
 
 // This test exposes an ARM specific problem in the interpreter, see
 // https://github.com/llvm/llvm-project/issues/94994.
-#ifndef __arm__
 TEST_F(InterpreterTest, Value) {
   std::vector<const char *> Args = {"-fno-sized-deallocation"};
   std::unique_ptr<Interpreter> Interp = createInterpreter(Args);
@@ -383,6 +382,5 @@ TEST_F(InterpreterTest, Value) {
   EXPECT_EQ(V9.getKind(), Value::K_PtrOrObj);
   EXPECT_TRUE(V9.isManuallyAlloc());
 }
-#endif /* ifndef __arm__ */
 
 } // end anonymous namespace

``````````

</details>


https://github.com/llvm/llvm-project/pull/96900


More information about the cfe-commits mailing list