[clang] [clang-repl] Fix Value for platforms where unqualified char is unsigned (PR #86118)
Stefan Gränitz via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 22 04:24:55 PDT 2024
https://github.com/weliveindetail updated https://github.com/llvm/llvm-project/pull/86118
>From 0b7f4bc8bf57219f5f1e5ffa06c986beb16b9546 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Thu, 21 Mar 2024 14:04:10 +0100
Subject: [PATCH 1/3] Add reproducer
---
clang/unittests/Interpreter/InterpreterTest.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index e76c0677db5ead..25f6e4f900c882 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -340,6 +340,11 @@ TEST(InterpreterTest, Value) {
EXPECT_EQ(V1.getKind(), Value::K_Int);
EXPECT_FALSE(V1.isManuallyAlloc());
+ Value V1b;
+ llvm::cantFail(Interp->ParseAndExecute("char x = 42;"));
+ llvm::cantFail(Interp->ParseAndExecute("c", &V1b));
+ EXPECT_TRUE(V1b.getKind() == Value::K_Char_S);
+
Value V2;
llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
llvm::cantFail(Interp->ParseAndExecute("y", &V2));
>From eace13b5c95680feeab7792eab675e8dd56a56ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Thu, 21 Mar 2024 14:05:05 +0100
Subject: [PATCH 2/3] Add missing REPL_BUILTIN_TYPE
---
clang/include/clang/Interpreter/Value.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/include/clang/Interpreter/Value.h b/clang/include/clang/Interpreter/Value.h
index c380cd91550def..d70e8f8719026b 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -76,6 +76,7 @@ class QualType;
X(bool, Bool) \
X(char, Char_S) \
X(signed char, SChar) \
+ X(unsigned char, Char_U) \
X(unsigned char, UChar) \
X(short, Short) \
X(unsigned short, UShort) \
>From 7db25a9f186818297d3ec0e7d3deff67e4549927 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Thu, 21 Mar 2024 14:33:50 +0100
Subject: [PATCH 3/3] Accept signed or unsigned for unqualified char in
reproducer
---
clang/unittests/Interpreter/InterpreterTest.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 25f6e4f900c882..69bc2da242884e 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -341,9 +341,10 @@ TEST(InterpreterTest, Value) {
EXPECT_FALSE(V1.isManuallyAlloc());
Value V1b;
- llvm::cantFail(Interp->ParseAndExecute("char x = 42;"));
+ llvm::cantFail(Interp->ParseAndExecute("char c = 42;"));
llvm::cantFail(Interp->ParseAndExecute("c", &V1b));
- EXPECT_TRUE(V1b.getKind() == Value::K_Char_S);
+ EXPECT_TRUE(V1b.getKind() == Value::K_Char_S ||
+ V1b.getKind() == Value::K_Char_U);
Value V2;
llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
More information about the cfe-commits
mailing list