From 0fa063816818ac53a0015a5d2b0328812005b40e Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 26 Jan 2012 23:34:06 +0000 Subject: [PATCH] Turn off implicit truncation warning for compound assignment to bitfields; it might be reasonable in some cases, but it clearly doesn't make sense in some cases, like the included testcase. , part 2. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149095 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 4 ++-- test/Sema/constant-conversion.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 8d01352fd2..7579a5d0ee 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4053,8 +4053,8 @@ void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) { if (BO->isComparisonOp()) return AnalyzeComparison(S, BO); - // And with assignments and compound assignments. - if (BO->isAssignmentOp()) + // And with simple assignments. + if (BO->getOpcode() == BO_Assign) return AnalyzeAssignment(S, BO); } diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c index c97eb05cd1..e3097f8be3 100644 --- a/test/Sema/constant-conversion.c +++ b/test/Sema/constant-conversion.c @@ -71,4 +71,6 @@ void test7() { f.twoBits1 = ~1; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -2 to 2}} f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -3 to 1}} + f.twoBits1 &= ~1; // no-warning + f.twoBits2 &= ~2; // no-warning } -- 2.40.0