[PATCH] D80055: Diagnose union tail padding

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 15 18:29:17 PDT 2020


jfb created this revision.
jfb added reviewers: rsmith, hubert.reinterpretcast.
Herald added subscribers: cfe-commits, ributzka, dexonsmith, jkorous.
Herald added a project: clang.
jfb marked an inline comment as done.
jfb added inline comments.


================
Comment at: clang/test/CodeGen/union-tail-padding.c:9
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++17 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++2a -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+
----------------
This test, while it might be surprising, is testing the current behavior of clang. I haven't validated that it's correct for each standard.


>From a discussion in D68115 <https://reviews.llvm.org/D68115>, it seems like union tail padding is often surprising to folks, compiler implementors included. This new diagnostic, -Wunion-tail-padding, emits a diagnostic when a union's tail is left undefined when develoeprs might have reasonably expected that it would not be. I've included -Wunion-tail-padding under the umbrella of a new diagnostic group, -Wpadding, since it often seems like padding in general is a source of pain. In particular, padding can leak secret information to malicious attackers. Here we focus on the places where padding is *unitialized*, not where a structure or union has padding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80055

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ConstantEmitter.h
  clang/test/CodeGen/union-tail-padding.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80055.264402.patch
Type: text/x-patch
Size: 21117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200516/ff01578b/attachment-0001.bin>


More information about the cfe-commits mailing list