Author: Stefan Gränitz
Date: 2024-03-25T09:42:41+01:00
New Revision: aa962d67ee896f416e285a9298e45fc08ff95eef

URL: 
https://github.com/llvm/llvm-project/commit/aa962d67ee896f416e285a9298e45fc08ff95eef
DIFF: 
https://github.com/llvm/llvm-project/commit/aa962d67ee896f416e285a9298e45fc08ff95eef.diff

LOG: [clang-repl] Fix Value for platforms where unqualified char is unsigned 
(#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`.

Added: 
    

Modified: 
    clang/include/clang/Interpreter/Value.h
    clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 
    


################################################################################
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)                                                    
\

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index e76c0677db5ead..69bc2da242884e 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -340,6 +340,12 @@ TEST(InterpreterTest, Value) {
   EXPECT_EQ(V1.getKind(), Value::K_Int);
   EXPECT_FALSE(V1.isManuallyAlloc());
 
+  Value V1b;
+  llvm::cantFail(Interp->ParseAndExecute("char c = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("c", &V1b));
+  EXPECT_TRUE(V1b.getKind() == Value::K_Char_S ||
+              V1b.getKind() == Value::K_Char_U);
+
   Value V2;
   llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
   llvm::cantFail(Interp->ParseAndExecute("y", &V2));


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to