From d1fd52a88fb495883da7b978f66a146462648d0f Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 23 May 2015 01:32:17 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238083 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 2 +- test/Sema/atomic-compare.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index a64932b1c7..23a6fc3c4c 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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(OtherT)) + if (const auto *AT = OtherT->getAs()) OtherT = AT->getValueType(); IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT); unsigned OtherWidth = OtherRange.Width; diff --git a/test/Sema/atomic-compare.c b/test/Sema/atomic-compare.c index 2eed091260..01eb820047 100644 --- a/test/Sema/atomic-compare.c +++ b/test/Sema/atomic-compare.c @@ -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 +} -- 2.40.0