[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
Thu Mar 21 06:40:26 PDT 2024
https://github.com/weliveindetail created https://github.com/llvm/llvm-project/pull/86118
Signedness of unqualified `char` is unspecified and varies between platforms. This patch adds `Char_U` in `REPL_BUILTIN_TYPES` to account for platforms that default to `unsigned char`.
>From e0cdd176e35d0bd255d1394eff6bee314c0e3cd6 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 fa3d6e1973c5d2fe13c85993cf851f18e41f0f32 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 3ade711f907758814d13852edae71cec746fcb7b 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 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 25f6e4f900c882..4b5d73769e5da7 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -343,7 +343,8 @@ TEST(InterpreterTest, Value) {
Value V1b;
llvm::cantFail(Interp->ParseAndExecute("char x = 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