This is an archive of the discontinued LLVM Phabricator instance.

Unify sanitizer kind representation between the driver and the rest of the compiler.
ClosedPublic

Authored by pcc on May 8 2015, 1:06 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 25363.May 8 2015, 1:06 PM
pcc retitled this revision from to Unify sanitizer kind representation between the driver and the rest of the compiler. No functional change..
pcc updated this object.
pcc edited the test plan for this revision. (Show Details)
pcc added a reviewer: samsonov.
pcc added a subscriber: Unknown Object (MLST).
samsonov added inline comments.May 8 2015, 1:33 PM
include/clang/Basic/Sanitizers.h
28 ↗(On Diff #25363)

Leave this named as SanitizerOrdinal, so that SO_ prefix makes sense.

49 ↗(On Diff #25363)

Fix comments to reflect that we're checking/setting sets of sanitizers now. However, I think we might still use two different entities for SanitizerKind and SanitizerMask....

62 ↗(On Diff #25363)

Any reason to make this public?

lib/CodeGen/CGExpr.cpp
2246 ↗(On Diff #25363)

That's the problem I see with using SanitizerMask instead of SanitizerKind class enum - sometimes (like in this case) we want to distinguish between a *single* sanitizer kind and a set of sanitizers. Here, for example, what should we return if Kind contains both Vptr and Return? Add a method that would tell you if SanitizerMask contains a single kind, and assert in this function?

2304 ↗(On Diff #25363)

Same here - what if SanitizeRecover is defined for some bits in Checked[i].second, and not defined for another?

pcc updated this revision to Diff 25372.May 8 2015, 2:33 PM
pcc retitled this revision from Unify sanitizer kind representation between the driver and the rest of the compiler. No functional change. to Unify sanitizer kind representation between the driver and the rest of the compiler..
pcc updated this object.
  • Address review comments
include/clang/Basic/Sanitizers.h
28 ↗(On Diff #25363)

Done.

49 ↗(On Diff #25363)

Fix comments to reflect that we're checking/setting sets of sanitizers now.

These functions are for single sanitizers only. I've added assertion checks to enforce that.

However, I think we might still use two different entities for SanitizerKind and SanitizerMask....

I don't think we need to do that. In my opinion it just makes things more confusing.

62 ↗(On Diff #25363)

It makes the code simpler, as we don't need accessor functions in every case where we need to do some bit operation on the mask.

lib/CodeGen/CGExpr.cpp
2246 ↗(On Diff #25363)

Add a method that would tell you if SanitizerMask contains a single kind, and assert in this function?

Yes. It makes more sense to add dynamic checks to the rare function that accepts a single sanitizer, than to use two different enums and try to make sure that the right one is being used everywhere.

2304 ↗(On Diff #25363)

Added an assertion check to SanitizerSet::has.

samsonov accepted this revision.May 8 2015, 3:42 PM
samsonov edited edge metadata.

Thanks for doing this! Feel free to apply after addressing comments below.

lib/CodeGen/CGExpr.cpp
3391 ↗(On Diff #25372)

Looks like you don't need this cast (you don't have them in other places).

lib/Driver/SanitizerArgs.cpp
113 ↗(On Diff #25372)

Please add parens: (Sanitizers.Mask & NeedsUbsanRt)

120 ↗(On Diff #25372)

ditto

147 ↗(On Diff #25372)

Consider using SanitizerMask type for local variables where appropriate

444 ↗(On Diff #25372)

clang-format this patch

This revision is now accepted and ready to land.May 8 2015, 3:42 PM
This revision was automatically updated to reflect the committed changes.
pcc added inline comments.May 11 2015, 2:42 PM
lib/CodeGen/CGExpr.cpp
3391 ↗(On Diff #25372)

Removed

lib/Driver/SanitizerArgs.cpp
113 ↗(On Diff #25372)

Done

120 ↗(On Diff #25372)

Done

147 ↗(On Diff #25372)

Done

444 ↗(On Diff #25372)

Done