This change adds "!ubsan" metadata to all the instructions
generated by Clang CodeGen to implement variety of UBSan checks. This
metadata can later be used by ASan instrumentation pass in LLVM backend
to avoid instrumenting UBSan-generated code. This should fix PR20085.
Details
- Reviewers
rsmith
Diff Detail
Event Timeline
tools/clang/lib/CodeGen/CGExprScalar.cpp | ||
---|---|---|
839 | Several callers of this are only guarding their call to this function; how about sinking the SanitizerScope down into here (and teaching the scope to cope with multiple SanitizerScope objects being live at once)? | |
tools/clang/lib/CodeGen/CodeGenFunction.cpp | ||
1660 | It seems more future-safe to pick a more general name for this, describing its functionality not this particular use case. Maybe "nosanitize"? |
tools/clang/lib/CodeGen/CGExprScalar.cpp | ||
---|---|---|
839 | On the contrary, there are no callers that have SanitizerScope only to guard the call to this function. Consider: EmitBinOpCheck(Builder.CreateICmpULE(RHS, GetWidthMinusOneValue(Ops.LHS, RHS)), Ops); we want to attach metadata to ICmpULE instruction created in this line. This is my main motivation for using asserts instead of re-entrant sanitizer scopes - if one adds a new UBSan check and writes the code like: if (SanOpts->SanitizeFoo) { Bar = Builder.CreateBar(); Baz = Builder.CreateBaz(Bar); EmitBinOpCheck(Baz, Info); } this will die with an assertion failure. If we allow multiple scopes, we won't notice missing metadata for bar and baz instructions. | |
tools/clang/lib/CodeGen/CodeGenFunction.cpp | ||
1660 | Sounds good. |
tools/clang/lib/CodeGen/CGExprScalar.cpp | ||
---|---|---|
839 | Thanks, you're quite right :) |
Rename !ubsan metadata to more generic and appropriate !nosanitize.
tools/clang/lib/CodeGen/CodeGenFunction.cpp | ||
---|---|---|
1660 | Done. |
Several callers of this are only guarding their call to this function; how about sinking the SanitizerScope down into here (and teaching the scope to cope with multiple SanitizerScope objects being live at once)?