r179600 - Fix handling of atomic shift operations, from Serge Pavlov.

Douglas Gregor dgregor at apple.com
Tue Apr 16 08:41:08 PDT 2013


Author: dgregor
Date: Tue Apr 16 10:41:08 2013
New Revision: 179600

URL: http://llvm.org/viewvc/llvm-project?rev=179600&view=rev
Log:
Fix handling of atomic shift operations, from Serge Pavlov.

Added:
    cfe/trunk/test/Sema/atomic-expr.c   (with props)
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=179600&r1=179599&r2=179600&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Apr 16 10:41:08 2013
@@ -6892,18 +6892,6 @@ QualType Sema::CheckShiftOperands(ExprRe
                                   bool IsCompAssign) {
   checkArithmeticNull(*this, LHS, RHS, Loc, /*isCompare=*/false);
 
-  // C99 6.5.7p2: Each of the operands shall have integer type.
-  if (!LHS.get()->getType()->hasIntegerRepresentation() || 
-      !RHS.get()->getType()->hasIntegerRepresentation())
-    return InvalidOperands(Loc, LHS, RHS);
-
-  // C++0x: Don't allow scoped enums. FIXME: Use something better than
-  // hasIntegerRepresentation() above instead of this.
-  if (isScopedEnumerationType(LHS.get()->getType()) ||
-      isScopedEnumerationType(RHS.get()->getType())) {
-    return InvalidOperands(Loc, LHS, RHS);
-  }
-
   // Vector shifts promote their scalar inputs to vector type.
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType())
@@ -6925,7 +6913,19 @@ QualType Sema::CheckShiftOperands(ExprRe
   RHS = UsualUnaryConversions(RHS.take());
   if (RHS.isInvalid())
     return QualType();
+  QualType RHSType = RHS.get()->getType();
 
+  // C99 6.5.7p2: Each of the operands shall have integer type.
+  if (!LHSType->hasIntegerRepresentation() ||
+      !RHSType->hasIntegerRepresentation())
+    return InvalidOperands(Loc, LHS, RHS);
+
+  // C++0x: Don't allow scoped enums. FIXME: Use something better than
+  // hasIntegerRepresentation() above instead of this.
+  if (isScopedEnumerationType(LHSType) ||
+      isScopedEnumerationType(RHSType)) {
+    return InvalidOperands(Loc, LHS, RHS);
+  }
   // Sanity-check shift operands
   DiagnoseBadShiftValues(*this, LHS, RHS, Loc, Opc, LHSType);
 

Added: cfe/trunk/test/Sema/atomic-expr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/atomic-expr.c?rev=179600&view=auto
==============================================================================
--- cfe/trunk/test/Sema/atomic-expr.c (added)
+++ cfe/trunk/test/Sema/atomic-expr.c Tue Apr 16 10:41:08 2013
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// expected-no-diagnostics
+
+_Atomic(unsigned int) data1;
+int _Atomic data2;
+
+// Shift operations
+
+int func_01 (int x) {
+  return data1 << x;
+}
+
+int func_02 (int x) {
+  return x << data1;
+}
+
+int func_03 (int x) {
+  return data2 << x;
+}
+
+int func_04 (int x) {
+  return x << data2;
+}
+
+int func_05 () {
+  return data2 << data1;
+}
+
+int func_06 () {
+  return data1 << data2;
+}
+
+void func_07 (int x) {
+  data1 <<= x;
+}
+
+void func_08 (int x) {
+  data2 <<= x;
+}
+
+void func_09 (int* xp) {
+  *xp <<= data1;
+}
+
+void func_10 (int* xp) {
+  *xp <<= data2;
+}

Propchange: cfe/trunk/test/Sema/atomic-expr.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Sema/atomic-expr.c
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Sema/atomic-expr.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list