[Sema] Diagnose default-initialization, destruction, and copying of
authorAkira Hatanaka <ahatanaka@apple.com>
Sat, 7 Sep 2019 00:34:43 +0000 (00:34 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Sat, 7 Sep 2019 00:34:43 +0000 (00:34 +0000)
commit090510608da404a0e1c80fa29eb5fc18f2d91755
treeee1fa58adc447633d137c6e364f148449955b8e1
parent0e881b9f5d1fd3c615f79860eacedaecad03daea
[Sema] Diagnose default-initialization, destruction, and copying of
non-trivial C union types

This recommits r365985, which was reverted because it broke a few
projects using unions containing non-trivial ObjC pointer fields in
system headers. We now have a patch to fix the problem (see
https://reviews.llvm.org/D65256).

Original commit message:

This patch diagnoses uses of non-trivial C unions and structs/unions
containing non-trivial C unions in the following contexts, which require
default-initialization, destruction, or copying of the union objects,
instead of disallowing fields of non-trivial types in C unions, which is
what we currently do:

- function parameters.
- function returns.
- assignments.
- compound literals.
- block captures except capturing of `__block` variables by non-escaping blocks.
- local and global variable definitions.
- lvalue-to-rvalue conversions of volatile types.

See the discussion in https://reviews.llvm.org/D62988 for more background.

rdar://problem/50679094

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

llvm-svn: 371275
18 files changed:
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/CodeGenObjC/Inputs/strong_in_union.h [deleted file]
clang/test/CodeGenObjC/strong-in-c-struct.m
clang/test/PCH/non-trivial-c-union.m [new file with mode: 0644]
clang/test/SemaObjC/arc-decls.m
clang/test/SemaObjC/non-trivial-c-union.m [new file with mode: 0644]