sepavloff added you to the CC list for the revision "Fix to PR15537 - assertion 
failure when comparing atomic unsigned int to int.".

Hi doug.gregor, rtrieu,

This patch fixes PR15537: clang assertion failure "comparison with mismatched 
types" whenc comparing atomic unsigned int to int. Handling of atomic types is 
made similar to that in CheckSingleAssignmentConstraints.

Could you please review the fix?
Thank you.

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

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

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -7126,6 +7126,15 @@
     }
   }
 
+  if (LHSType->isAtomicType()) {
+    LHS = DefaultLvalueConversion(LHS.take());
+    LHSType = LHS.get()->getType();
+  }
+  if (RHSType->isAtomicType()) {
+      RHS = DefaultLvalueConversion(RHS.take());
+      RHSType = RHS.get()->getType();
+  }
+
   // C99 6.5.8p3 / C99 6.5.9p4
   if (LHS.get()->getType()->isArithmeticType() &&
       RHS.get()->getType()->isArithmeticType()) {
Index: test/Sema/atomic-expr.c
===================================================================
--- /dev/null
+++ test/Sema/atomic-expr.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// PR15537
+
+_Atomic(unsigned int) data1 = 0;
+_Atomic(int) data2 = 0;
+
+int func_1 () {
+  return data1 == 0;
+}
+
+int func_2 (_Atomic(int) * ptr) {
+  return *ptr < data1;
+}
+
+int func_3 () {
+  return data1 <= data2;
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -7126,6 +7126,15 @@
     }
   }
 
+  if (LHSType->isAtomicType()) {
+    LHS = DefaultLvalueConversion(LHS.take());
+    LHSType = LHS.get()->getType();
+  }
+  if (RHSType->isAtomicType()) {
+      RHS = DefaultLvalueConversion(RHS.take());
+      RHSType = RHS.get()->getType();
+  }
+
   // C99 6.5.8p3 / C99 6.5.9p4
   if (LHS.get()->getType()->isArithmeticType() &&
       RHS.get()->getType()->isArithmeticType()) {
Index: test/Sema/atomic-expr.c
===================================================================
--- /dev/null
+++ test/Sema/atomic-expr.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// PR15537
+
+_Atomic(unsigned int) data1 = 0;
+_Atomic(int) data2 = 0;
+
+int func_1 () {
+  return data1 == 0;
+}
+
+int func_2 (_Atomic(int) * ptr) {
+  return *ptr < data1;
+}
+
+int func_3 () {
+  return data1 <= data2;
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to