hanchenye-llvm-project/clang/docs
Roman Lebedev 62debd8055 [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part
This is the second half of Implicit Integer Conversion Sanitizer.
It completes the first half, and finally makes the sanitizer
fully functional! Only the bitfield handling is missing.

Summary:
C and C++ are interesting languages. They are statically typed, but weakly.
The implicit conversions are allowed. This is nice, allows to write code
while balancing between getting drowned in everything being convertible,
and nothing being convertible. As usual, this comes with a price:

```
void consume(unsigned int val);

void test(int val) {
  consume(val);
  // The 'val' is `signed int`, but `consume()` takes `unsigned int`.
  // If val is negative, then consume() will be operating on a large
  // unsigned value, and you may or may not have a bug.

  // But yes, sometimes this is intentional.
  // Making the conversion explicit silences the sanitizer.
  consume((unsigned int)val);
}
```

Yes, there is a `-Wsign-conversion`` diagnostic group, but first, it is kinda
noisy, since it warns on everything (unlike sanitizers, warning on an
actual issues), and second, likely there are cases where it does **not** warn.

The actual detection is pretty easy. We just need to check each of the values
whether it is negative, and equality-compare the results of those comparisons.
The unsigned value is obviously non-negative. Zero is non-negative too.
https://godbolt.org/g/w93oj2

We do not have to emit the check *always*, there are obvious situations
where we can avoid emitting it, since it would **always** get optimized-out.
But i do think the tautological IR (`icmp ult %x, 0`, which is always false)
should be emitted, and the middle-end should cleanup it.

This sanitizer is in the `-fsanitize=implicit-conversion` group,
and is a logical continuation of D48958 `-fsanitize=implicit-integer-truncation`.
As for the ordering, i'we opted to emit the check **after**
`-fsanitize=implicit-integer-truncation`. At least on these simple 16 test cases,
this results in 1 of the 12 emitted checks being optimized away,
as compared to 0 checks being optimized away if the order is reversed.

This is a clang part.
The compiler-rt part is D50251.

Finishes fixing [[ https://bugs.llvm.org/show_bug.cgi?id=21530 | PR21530 ]], [[ https://bugs.llvm.org/show_bug.cgi?id=37552 | PR37552 ]], [[ https://bugs.llvm.org/show_bug.cgi?id=35409 | PR35409 ]].
Finishes partially fixing [[ https://bugs.llvm.org/show_bug.cgi?id=9821 | PR9821 ]].
Finishes fixing https://github.com/google/sanitizers/issues/940.

Only the bitfield handling is missing.

Reviewers: vsk, rsmith, rjmccall, #sanitizers, erichkeane

Reviewed By: rsmith

Subscribers: chandlerc, filcab, cfe-commits, regehr

Tags: #sanitizers, #clang

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

llvm-svn: 345660
2018-10-30 21:58:56 +00:00
..
CommandGuide [diagtool] Add diagtool to install target. 2018-05-16 10:23:25 +00:00
analyzer [analyzer] Add a testing facility for testing relationships between symbols. 2018-09-25 23:50:53 +00:00
tools Remove non-existant typeloc matchers from documentation 2018-10-09 08:24:18 +00:00
AddressSanitizer.rst [Docs] Update supported oses for safestack, ubsan, asan, tsan and msan 2018-07-25 13:55:06 +00:00
AttributeReference.rst
AutomaticReferenceCounting.rst Fix and improve the ARC spec's wording about unmanaged objects. 2018-07-20 05:40:09 +00:00
Block-ABI-Apple.rst [CodeGen][ObjC] Make copying and disposing of a non-escaping block 2018-07-20 17:10:32 +00:00
Block-ABI-Apple.txt
BlockLanguageSpec.rst
CMakeLists.txt
ClangCheck.rst
ClangCommandLineReference.rst [Hexagon] Remove support for V4 2018-10-19 15:36:45 +00:00
ClangFormat.rst [Docs] Update list of languages clang-format can format 2017-11-22 10:47:35 +00:00
ClangFormatStyleOptions.rst Update the example of BS_Stroustrup to match what is done by clang-format 2018-10-26 07:25:37 +00:00
ClangPlugins.rst
ClangTools.rst
ControlFlowIntegrity.rst Implement CFI for indirect calls via a member function pointer. 2018-06-26 02:15:47 +00:00
ControlFlowIntegrityDesign.rst Introduce the VTable interleaving scheme to the CFI design documentation 2018-09-11 20:43:52 +00:00
CrossCompilation.rst
DataFlowSanitizer.rst
DataFlowSanitizerDesign.rst
DiagnosticsReference.rst [Diagnostic] Fix a warning typo. NFC. 2018-09-12 18:27:21 +00:00
DriverArchitecture.png
DriverInternals.rst
ExternalClangExamples.rst
FAQ.rst
HardwareAssistedAddressSanitizerDesign.rst [docs] Don't use the `asm` syntax highlighting (which our docs builder 2018-08-06 01:28:42 +00:00
HowToSetupToolingForLLVM.rst Allow the creation of human-friendly ASTDumper to arbitrary output stream 2018-04-06 13:01:12 +00:00
InternalsManual.rst Remove stale documentation from InternalsManual.rst 2018-07-24 16:11:30 +00:00
IntroductionToTheClangAST.rst
ItaniumMangleAbiTags.rst
JSONCompilationDatabase.rst [Tooling] Use FixedCompilationDatabase when `compile_flags.txt` is found. 2017-11-09 10:37:39 +00:00
LTOVisibility.rst Implement CFI for indirect calls via a member function pointer. 2018-06-26 02:15:47 +00:00
LanguageExtensions.rst Revert "Revert "Support for groups of attributes in #pragma clang attribute"" 2018-10-29 17:38:42 +00:00
LeakSanitizer.rst
LibASTMatchers.rst
LibASTMatchersReference.html Add the isStaticLocal() AST matcher for matching on local static variables. 2018-10-29 13:47:56 +00:00
LibASTMatchersTutorial.rst Update CMakeLists.txt snippet so that example compiles 2018-10-01 20:28:07 +00:00
LibFormat.rst Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
LibTooling.rst Add missing newlines to cl::extrahelp uses 2018-05-08 19:46:29 +00:00
MSVCCompatibility.rst
Makefile.sphinx
MemorySanitizer.rst [Docs] Update supported oses for safestack, ubsan, asan, tsan and msan 2018-07-25 13:55:06 +00:00
Modules.rst [Modules] Add platform and environment features to requires clause 2018-09-18 17:11:13 +00:00
ObjectiveCLiterals.rst
OpenMPSupport.rst [OPENMP] What's new for OpenMP in clang. 2018-07-26 17:53:45 +00:00
PCHInternals.rst
PCHLayout.graffle
PCHLayout.png
PTHInternals.rst
RAVFrontendAction.rst Port getLocStart -> getBeginLoc 2018-08-09 21:08:08 +00:00
README.txt
RefactoringEngine.rst
ReleaseNotes.rst [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part 2018-10-30 21:58:56 +00:00
SafeStack.rst [Docs] Update supported oses for safestack, ubsan, asan, tsan and msan 2018-07-25 13:55:06 +00:00
SanitizerCoverage.rst
SanitizerSpecialCaseList.rst
SanitizerStats.rst [docs] -fsanitize=cfi only allowed with -fvisibility= 2018-06-15 23:11:18 +00:00
ShadowCallStack.rst [ShadowCallStack] fix the docs 2018-05-01 00:15:56 +00:00
SourceBasedCodeCoverage.rst
ThinLTO.rst [ThinLTO] Correct documentation on default number of threads 2018-08-17 13:19:36 +00:00
ThreadSafetyAnalysis.rst
ThreadSanitizer.rst Fix tsan doc 2018-07-25 14:27:14 +00:00
Toolchain.rst [Docs] Fix typo in toolchain documentation 2018-01-12 02:57:02 +00:00
Tooling.rst
UndefinedBehaviorSanitizer.rst [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part 2018-10-30 21:58:56 +00:00
UsersManual.rst [Doc] fix second error in UsersManual 2018-10-12 17:57:18 +00:00
conf.py Update docs version and clear release notes after 8.0.0 version bump 2018-08-01 14:01:27 +00:00
doxygen-mainpage.dox
doxygen.cfg.in Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
index.rst Add the -fsanitize=shadow-call-stack flag 2018-04-03 22:33:53 +00:00
make.bat

README.txt

See llvm/docs/README.txt