]> granicus.if.org Git - clang/commitdiff
[Sema] Don't use dyn_cast to detect an AtomicType
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 23 May 2015 01:32:17 +0000 (01:32 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 23 May 2015 01:32:17 +0000 (01:32 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238083 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/atomic-compare.c

index a64932b1c7176a813eee54ee116120edad4f3792..23a6fc3c4cd43f35a1dd388655d2a83f034e6b57 100644 (file)
@@ -6100,7 +6100,7 @@ static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E,
   // 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;
index 2eed091260267d3002d490ac695a3b2bfe5d383b..01eb8200472560fe24e0bffe8736e9cd92628ae1 100644 (file)
@@ -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
+}