[PATCH] Handle atomic types in Type::hasIntegerRepresentation()

Serge Pavlov sepavloff at gmail.com
Tue Apr 16 07:54:41 PDT 2013


  OK, I see the point.
  This is different implementation that touches only Sema::CheckShiftOperands.
  The idea is to call UsualUnaryConversion before call to hasFloatingRepresentation.

Hi doug.gregor,

http://llvm-reviews.chandlerc.com/D673

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D673?vs=1637&id=1644#toc

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/atomic-expr.c

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6892,18 +6892,6 @@
                                   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 @@
   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);
 
Index: test/Sema/atomic-expr.c
===================================================================
--- /dev/null
+++ test/Sema/atomic-expr.c
@@ -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;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D673.2.patch
Type: text/x-patch
Size: 2492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130416/44aed8db/attachment.bin>


More information about the cfe-commits mailing list