]> granicus.if.org Git - clang/commitdiff
Fix PR2279 part C: shifts don't perform the UACs, thanks to Neil
authorChris Lattner <sabre@nondot.org>
Sun, 4 May 2008 18:25:32 +0000 (18:25 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 4 May 2008 18:25:32 +0000 (18:25 +0000)
for pointing this out.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50624 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPExpressions.cpp
test/Preprocessor/expr_usual_conversions.c

index 631701513775554cba2edfb2ee504707c933781f..6343a3c09839646356673224bacd524f13ca46b7 100644 (file)
@@ -409,9 +409,11 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec,
     assert(PeekPrec <= ThisPrec && "Recursion didn't work!");
     
     // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
-    // either operand is unsigned.  Don't do this for x and y in "x ? y : z".
+    // either operand is unsigned.  Don't do this for x and y in "x ? y : z" or
+    // for shifts.
     llvm::APSInt Res(LHS.getBitWidth());
-    if (Operator != tok::question) {
+    if (Operator != tok::question && Operator != tok::lessless &&
+        Operator != tok::greatergreater) {
       Res.setIsUnsigned(LHS.isUnsigned()|RHS.isUnsigned());
       // If this just promoted something from signed to unsigned, and if the
       // value was negative, warn about it.
index b2ccc40900752f89d21de83bcf2e15c28bcfbd6c..90275c99444440902d548309060af9ef6dca66e7 100644 (file)
@@ -6,3 +6,8 @@
 foo
 #endif
 
+// Shifts don't want the usual conversions: PR2279
+#if (2 << 1U) - 30 >= 0
+#error
+#endif
+