r238083 - [Sema] Don't use dyn_cast to detect an AtomicType

David Majnemer david.majnemer at gmail.com
Fri May 22 18:32:17 PDT 2015


Author: majnemer
Date: Fri May 22 20:32:17 2015
New Revision: 238083

URL: http://llvm.org/viewvc/llvm-project?rev=238083&view=rev
Log:
[Sema] Don't use dyn_cast to detect an AtomicType

An AtomicType might be hidden behind arbitrary levels of typedefs.
getAs<> will reliably walk through the sugar to get the underlying
AtomicType.

This fixes PR23638.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/atomic-compare.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=238083&r1=238082&r2=238083&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri May 22 20:32:17 2015
@@ -6100,7 +6100,7 @@ static void DiagnoseOutOfRangeComparison
   // TODO: Investigate using GetExprRange() to get tighter bounds
   // on the bit ranges.
   QualType OtherT = Other->getType();
-  if (const AtomicType *AT = dyn_cast<AtomicType>(OtherT))
+  if (const auto *AT = OtherT->getAs<AtomicType>())
     OtherT = AT->getValueType();
   IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
   unsigned OtherWidth = OtherRange.Width;

Modified: cfe/trunk/test/Sema/atomic-compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/atomic-compare.c?rev=238083&r1=238082&r2=238083&view=diff
==============================================================================
--- cfe/trunk/test/Sema/atomic-compare.c (original)
+++ cfe/trunk/test/Sema/atomic-compare.c Fri May 22 20:32:17 2015
@@ -19,3 +19,8 @@ void f(_Atomic(int) a, _Atomic(int) b) {
   if (!a > b)     {} // no warning
   if (!a > -1)    {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
 }
+
+typedef _Atomic(int) Ty;
+void PR23638(Ty *a) {
+  if (*a == 1) {} // no warning
+}





More information about the cfe-commits mailing list