]> granicus.if.org Git - clang/commit
_Atomic of empty struct shouldn't assert
authorJF Bastien <jfb@google.com>
Wed, 9 May 2018 03:51:12 +0000 (03:51 +0000)
committerJF Bastien <jfb@google.com>
Wed, 9 May 2018 03:51:12 +0000 (03:51 +0000)
commit49d557c3652a0113159c2d4442391835a2e220e3
treed8e5df5b1142c32a51a35c2eaa46fb84ec35f0a3
parentdc29e8eb7ed26d02637d2d7d08e13925187facc2
_Atomic of empty struct shouldn't assert

Summary:

An _Atomic of an empty struct is pretty silly. In general we just widen empty
structs to hold a byte's worth of storage, and we represent size and alignment
as 0 internally and let LLVM figure out what to do. For _Atomic it's a bit
different: the memory model mandates concrete effects occur when atomic
operations occur, so in most cases actual instructions need to get emitted. It's
really not worth trying to optimize empty struct atomics by figuring out e.g.
that a fence would do, even though sane compilers should do optimize atomics.
Further, wg21.link/p0528 will fix C++20 atomics with padding bits so that
cmpxchg on them works, which means that we'll likely need to do the zero-init
song and dance for empty atomic structs anyways (and I think we shouldn't
special-case this behavior to C++20 because prior standards are just broken).

This patch therefore makes a minor change to r176658 "Promote atomic type sizes
up to a power of two": if the width of the atomic's value type is 0, just use 1
byte for width and leave alignment as-is (since it should never be zero, and
over-aligned zero-width structs are weird but fine).

This fixes an assertion:
   (NumBits >= MIN_INT_BITS && "bitwidth too small"), function get, file ../lib/IR/Type.cpp, line 241.

It seems like this has run into other assertions before (namely the unreachable
Kind check in ImpCastExprToType), but I haven't reproduced that issue with
tip-of-tree.

<rdar://problem/39678063>

Reviewers: arphaman, rjmccall

Subscribers: aheejin, cfe-commits

Differential Revision: https://reviews.llvm.org/D46613

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331845 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/ASTContext.cpp
test/CodeGen/c11atomics-ios.c
test/CodeGen/c11atomics.c