]> granicus.if.org Git - clang/commit
[clang][CodeGen] Implicit Conversion Sanitizer: discover the world of CompoundAssign...
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 19 Nov 2018 19:56:43 +0000 (19:56 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 19 Nov 2018 19:56:43 +0000 (19:56 +0000)
commitd8a18b8bb0023a295456958e267e84ba1d1f3d1f
treeaea90378a627e2146b64a27408ebb1d5d0b1c524
parent543b703ebe2d8b28fc8602a619304637443879ac
[clang][CodeGen] Implicit Conversion Sanitizer: discover the world of CompoundAssign operators

Summary:
As reported by @regehr (thanks!) on twitter (https://twitter.com/johnregehr/status/1057681496255815686),
we (me) has completely forgot about the binary assignment operator.
In AST, it isn't represented as separate `ImplicitCastExpr`'s,
but as a single `CompoundAssignOperator`, that does all the casts internally.
Which means, out of these two, only the first one is diagnosed:
```
auto foo() {
    unsigned char c = 255;
    c = c + 1;
    return c;
}
auto bar() {
    unsigned char c = 255;
    c += 1;
    return c;
}
```
https://godbolt.org/z/JNyVc4

This patch does handle the `CompoundAssignOperator`:
```
int main() {
  unsigned char c = 255;
  c += 1;
  return c;
}
```
```
$ ./bin/clang -g -fsanitize=integer /tmp/test.c && ./a.out
/tmp/test.c:3:5: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
    #0 0x2392b8 in main /tmp/test.c:3:5
    #1 0x7fec4a612b16 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x22b16)
    #2 0x214029 in _start (/build/llvm-build-GCC-release/a.out+0x214029)
```

However, the pre/post increment/decrement is still not handled.

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

Reviewed By: rjmccall

Subscribers: mclow.lists, cfe-commits, regehr

Tags: #clang, #sanitizers

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347258 91177308-0d34-0410-b5e6-96231b3b80d8
docs/ReleaseNotes.rst
lib/CodeGen/CGExprScalar.cpp
test/CodeGen/catch-implicit-integer-sign-changes-CompoundAssignOperator.c [new file with mode: 0644]
test/CodeGen/catch-implicit-integer-truncations-CompoundAssignOperator.c [new file with mode: 0644]
test/CodeGen/catch-implicit-signed-integer-truncation-or-sign-change-CompoundAssignOperator.c [new file with mode: 0644]