From edb9fbb78a18d796e497e83ff912b19d064cf5a1 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 7 Sep 2018 21:24:27 +0000 Subject: [PATCH] Make -Watomic-alignment say whether the atomic operation was oversized or misaligned. llvm-svn: 341710 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++-- clang/lib/CodeGen/CGAtomic.cpp | 12 ++++++++---- clang/test/CodeGen/atomics-sema-alignment.c | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 78d1b0f..9945b22 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7093,8 +7093,8 @@ def warn_atomic_op_has_invalid_memory_order : Warning< def err_atomic_op_has_invalid_synch_scope : Error< "synchronization scope argument to atomic operation is invalid">; def warn_atomic_op_misaligned : Warning< - "misaligned or large atomic operation may incur significant performance penalty">, - InGroup>; + "%select{large|misaligned}0 atomic operation may incur " + "significant performance penalty">, InGroup>; def err_overflow_builtin_must_be_int : Error< "operand argument to overflow builtin must be an integer (%0 invalid)">; diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp index eaf29df..5b63b3f 100644 --- a/clang/lib/CodeGen/CGAtomic.cpp +++ b/clang/lib/CodeGen/CGAtomic.cpp @@ -765,11 +765,15 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy); uint64_t Size = sizeChars.getQuantity(); unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth(); - bool UseLibcall = ((Ptr.getAlignment() % sizeChars) != 0 || - getContext().toBits(sizeChars) > MaxInlineWidthInBits); - if (UseLibcall) - CGM.getDiags().Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned); + bool Oversized = getContext().toBits(sizeChars) > MaxInlineWidthInBits; + bool Misaligned = (Ptr.getAlignment() % sizeChars) != 0; + bool UseLibcall = Misaligned | Oversized; + + if (UseLibcall) { + CGM.getDiags().Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned) + << !Oversized; + } llvm::Value *Order = EmitScalarExpr(E->getOrder()); llvm::Value *Scope = diff --git a/clang/test/CodeGen/atomics-sema-alignment.c b/clang/test/CodeGen/atomics-sema-alignment.c index 364743d..9443af3 100644 --- a/clang/test/CodeGen/atomics-sema-alignment.c +++ b/clang/test/CodeGen/atomics-sema-alignment.c @@ -12,10 +12,10 @@ typedef int __attribute__((aligned(1))) unaligned_int; void func(IntPair *p) { IntPair res; - __atomic_load(p, &res, 0); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} - __atomic_store(p, &res, 0); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} - __atomic_fetch_add((unaligned_int *)p, 1, 2); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} - __atomic_fetch_sub((unaligned_int *)p, 1, 3); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} + __atomic_load(p, &res, 0); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} + __atomic_store(p, &res, 0); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} + __atomic_fetch_add((unaligned_int *)p, 1, 2); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} + __atomic_fetch_sub((unaligned_int *)p, 1, 3); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} } void func1(LongStruct *p) { -- 2.7.4