From f89960b9e30096a9250ec2206c181613faf4302b Mon Sep 17 00:00:00 2001 From: Michael Wong Date: Tue, 24 Feb 2015 13:34:20 +0000 Subject: [PATCH] Commit patch for PR19649. Set the correct sign of wide character for literals based on underlying type of wchar_t. Reviewed: http://reviews.llvm.org/D7559 Patch by Rachel Craig; Test cases by Hubert Tong. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230333 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPExpressions.cpp | 4 +++- test/Preprocessor/pr19649-signed-wchar_t.c | 6 ++++++ test/Preprocessor/pr19649-unsigned-wchar_t.c | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/Preprocessor/pr19649-signed-wchar_t.c create mode 100644 test/Preprocessor/pr19649-unsigned-wchar_t.c diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index 9cf72cf8f8..a6f16f80b7 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -310,7 +310,9 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // Set the value. Val = Literal.getValue(); // Set the signedness. UTF-16 and UTF-32 are always unsigned - if (!Literal.isUTF16() && !Literal.isUTF32()) + if (Literal.isWide()) + Val.setIsUnsigned(!TargetInfo::isTypeSigned(TI.getWCharType())); + else if (!Literal.isUTF16() && !Literal.isUTF32()) Val.setIsUnsigned(!PP.getLangOpts().CharIsSigned); if (Result.Val.getBitWidth() > Val.getBitWidth()) { diff --git a/test/Preprocessor/pr19649-signed-wchar_t.c b/test/Preprocessor/pr19649-signed-wchar_t.c new file mode 100644 index 0000000000..f76f43163c --- /dev/null +++ b/test/Preprocessor/pr19649-signed-wchar_t.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -E -x c %s +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -E -fno-signed-char -x c %s + +#if (L'\0' - 1 > 0) +# error "Unexpected expression evaluation result" +#endif diff --git a/test/Preprocessor/pr19649-unsigned-wchar_t.c b/test/Preprocessor/pr19649-unsigned-wchar_t.c new file mode 100644 index 0000000000..4bbe1b57ce --- /dev/null +++ b/test/Preprocessor/pr19649-unsigned-wchar_t.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple i386-pc-cygwin -E -x c %s +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -E -fshort-wchar -x c %s + +#if (L'\0' - 1 < 0) +# error "Unexpected expression evaluation result" +#endif -- 2.40.0