[PATCH] Fix to PR15537 - assertion failure when comparing atomic unsigned int to int.

Serge Pavlov sepavloff at gmail.com
Sat Mar 30 06:35:48 PDT 2013


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;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D599.1.patch
Type: text/x-patch
Size: 1008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130330/92fd5237/attachment.bin>


More information about the cfe-commits mailing list