[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis
Gui Andrade via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 11 12:07:55 PDT 2020
guiand created this revision.
guiand added reviewers: eugenis, efriedma, nlopes, spatel, HAPPY.
Herald added subscribers: llvm-commits, cfe-commits, kerbowa, luismarques, apazos, sameer.abuasal, pzheng, s.egerton, lenary, Jim, jocewei, PkmX, jfb, dexonsmith, the_o, brucehoult, MartinMosbeck, rogfer01, steven_wu, atanasyan, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, fedor.sergeev, kbarton, aheejin, hiraditya, sbc100, nhaehnle, jvesely, nemanjai, jyknight.
Herald added projects: clang, LLVM.
This change adds a new IR `partialinit` attribute, introduced under the DisallowPoisonedCallArguments module flag. `partialinit` denotes when a function call argument or return val may legally contain uninitialized bits due to the ABI used by the frontend language. This particularly applies to padding in structs, and unions with different size members.
The presence or (deliberate) absence of this attribute allows the backend to conduct additional transformations at the call site, based on the presumption that poison values may only pass function boundaries in particular circumstances. These circumstances are marked with partialinit.
In MemorySanitizer, this attribute enables optimizations which decrease instrumented code size by up to 23% (measured with an instrumented build of clang) and runtime by an even larger proportion. I'll introduce the change allowing msan to take advantage of this information in a separate patch.
Changes in this patch include:
- Mark when union contains fields of different sizes
- Mark when struct contains internal or tail padding
- Mark when coercing to type of different size
- Selectively mark bitfields that don't fill storage type, and arrays with padded items
- Prevent bool types from being partialinit when wrapped in structs
- Mark when promoting arguments (can't know data's init state when behind a pointer or reference).
Test changes include:
- Clang CodeGen tests now look for presence of partialinit attribute where appropriate
- Argument promotion tests do the same
- Some tests were fixed to not rely on particular indices of module flags, which changed on adding DisallowPoisonedCallArguments
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D81678
Files:
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGRecordLayout.h
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/aapcs-align.cpp
clang/test/CodeGen/aapcs64-align.cpp
clang/test/CodeGen/aarch64-args.cpp
clang/test/CodeGen/aarch64-arguments-hfa-v3.c
clang/test/CodeGen/aarch64-varargs.c
clang/test/CodeGen/arc/arguments.c
clang/test/CodeGen/arm-aapcs-vfp.c
clang/test/CodeGen/arm-abi-vector.c
clang/test/CodeGen/arm-arguments.c
clang/test/CodeGen/arm-be-result-return.c
clang/test/CodeGen/arm-bf16-params-returns.c
clang/test/CodeGen/arm-fp16-arguments.c
clang/test/CodeGen/arm-homogenous.c
clang/test/CodeGen/arm-mangle-bf16.cpp
clang/test/CodeGen/arm64-abi-vector.c
clang/test/CodeGen/arm64-arguments.c
clang/test/CodeGen/arm64-be-bitfield.c
clang/test/CodeGen/arm64-microsoft-arguments.cpp
clang/test/CodeGen/arm64_32-vaarg.c
clang/test/CodeGen/arm_neon_intrinsics.c
clang/test/CodeGen/armv7k-abi.c
clang/test/CodeGen/catch-implicit-integer-sign-changes-incdec.c
clang/test/CodeGen/cmse-clear-arg.c
clang/test/CodeGen/cmse-clear-fp16.c
clang/test/CodeGen/ext-int-cc.c
clang/test/CodeGen/lanai-arguments.c
clang/test/CodeGen/mips-byval-arg.c
clang/test/CodeGen/mips64-class-return.cpp
clang/test/CodeGen/mips64-padding-arg.c
clang/test/CodeGen/ppc32-and-aix-struct-return.c
clang/test/CodeGen/ppc64-align-struct.c
clang/test/CodeGen/ppc64-soft-float.c
clang/test/CodeGen/ppc64-vector.c
clang/test/CodeGen/ppc64le-aggregates.c
clang/test/CodeGen/regcall.c
clang/test/CodeGen/renderscript.c
clang/test/CodeGen/riscv32-ilp32f-ilp32d-abi.c
clang/test/CodeGen/riscv64-lp64d-abi.c
clang/test/CodeGen/riscv64-lp64f-lp64d-abi.c
clang/test/CodeGen/sparcv9-abi.c
clang/test/CodeGen/systemz-abi-vector.c
clang/test/CodeGen/systemz-abi.c
clang/test/CodeGen/tbaa.cpp
clang/test/CodeGen/vectorcall.c
clang/test/CodeGen/wasm-arguments.c
clang/test/CodeGen/x86_32-arguments-darwin.c
clang/test/CodeGen/x86_32-arguments-iamcu.c
clang/test/CodeGen/x86_64-arguments-darwin.c
clang/test/CodeGen/x86_64-arguments-nacl.c
clang/test/CodeGen/x86_64-arguments.c
clang/test/CodeGenCUDA/flush-denormals.cu
clang/test/CodeGenCXX/aarch64-arguments.cpp
clang/test/CodeGenCXX/conditional-temporaries.cpp
clang/test/CodeGenCXX/ext-int.cpp
clang/test/CodeGenCXX/homogeneous-aggregates.cpp
clang/test/CodeGenCXX/inline-functions.cpp
clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
clang/test/CodeGenCXX/pragma-followup_inner.cpp
clang/test/CodeGenCXX/pragma-loop-predicate.cpp
clang/test/CodeGenCXX/trivial_abi.cpp
clang/test/CodeGenCXX/wasm-args-returns.cpp
clang/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp
clang/test/CodeGenCXX/x86_64-arguments.cpp
clang/test/CodeGenCoroutines/microsoft-abi-operator-coawait.cpp
clang/test/CodeGenObjC/arc.m
clang/test/CodeGenObjC/nontrivial-c-struct-exception.m
clang/test/CodeGenObjC/strong-in-c-struct.m
clang/test/CodeGenObjCXX/property-object-conditional-exp.mm
clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
clang/test/OpenMP/nvptx_unsupported_type_codegen.cpp
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/AsmParser/LLToken.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll
llvm/test/Transforms/ArgumentPromotion/X86/attributes.ll
llvm/test/Transforms/ArgumentPromotion/X86/min-legal-vector-width.ll
llvm/test/Transforms/ArgumentPromotion/aggregate-promote.ll
llvm/test/Transforms/ArgumentPromotion/attrs.ll
llvm/test/Transforms/ArgumentPromotion/basictest.ll
llvm/test/Transforms/ArgumentPromotion/byval-2.ll
llvm/test/Transforms/ArgumentPromotion/byval.ll
llvm/test/Transforms/ArgumentPromotion/chained.ll
llvm/test/Transforms/ArgumentPromotion/control-flow2.ll
llvm/test/Transforms/ArgumentPromotion/dbg.ll
llvm/test/Transforms/ArgumentPromotion/fp80.ll
llvm/test/Transforms/ArgumentPromotion/inalloca.ll
llvm/test/Transforms/ArgumentPromotion/invalidation.ll
llvm/test/Transforms/ArgumentPromotion/pr32917.ll
llvm/test/Transforms/ArgumentPromotion/profile.ll
llvm/test/Transforms/ArgumentPromotion/reserve-tbaa.ll
llvm/test/Transforms/ArgumentPromotion/sret.ll
llvm/test/Transforms/ArgumentPromotion/tail.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81678.270192.patch
Type: text/x-patch
Size: 246731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200611/1f675863/attachment-0001.bin>
More information about the cfe-commits
mailing list