69 lines · cpp
1// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \2// RUN: -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker=core.FixedAddressDereference3 4template <typename T> void clang_analyzer_dump(T);5using size_t = decltype(sizeof(int));6 7__attribute__((always_inline)) static inline constexpr unsigned int _castf32_u32(float __A) {8 return __builtin_bit_cast(unsigned int, __A); // no-warning9}10 11void test(int i) {12 _castf32_u32(42);13 14 float f = 42;15 16 // Loading from a floating point value results in unknown,17 // which later materializes as a conjured value.18 auto g = __builtin_bit_cast(unsigned int, f);19 clang_analyzer_dump(g);20 // expected-warning-re@-1 {{{{^conj_\$[0-9]+{unsigned int,}}}}21 22 auto g2 = __builtin_bit_cast(unsigned int, 42.0f);23 clang_analyzer_dump(g2);24 // expected-warning-re@-1 {{{{^conj_\$[0-9]+{unsigned int,}}}}25 26 auto g3 = __builtin_bit_cast(unsigned int, i);27 clang_analyzer_dump(g3);28 // expected-warning-re@-1 {{{{^reg_\$[0-9]+<int i>}}}}29 30 auto g4 = __builtin_bit_cast(unsigned long, &i);31 clang_analyzer_dump(g4);32 // expected-warning@-1 {{&i [as 64 bit integer]}}33}34 35struct A {36 int n;37 void set(int x) {38 n = x;39 }40};41void gh_69922(size_t p) {42 // expected-warning@+1 {{Unknown}}43 clang_analyzer_dump(__builtin_bit_cast(A*, p & 1));44 45 __builtin_bit_cast(A*, p & 1)->set(2); // no-crash46 // However, since the `this` pointer is expected to be a Loc, but we have47 // NonLoc there, we simply give up and resolve it as `Unknown`.48 // Then, inside the `set()` member function call we can't evaluate the49 // store to the member variable `n`.50 51 clang_analyzer_dump(__builtin_bit_cast(A*, p & 1)->n); // Ideally, this should print "2".52 // expected-warning@-1 {{Unknown}}53}54 55namespace {56 typedef unsigned long uintptr_t;57 58 bool previously_crash(const void *& ptr) {59 clang_analyzer_dump(__builtin_bit_cast(void*, static_cast<uintptr_t>(-1)));60 // expected-warning-re@-1 {{{{[0-9]+}} (Loc)}}61 return ptr == __builtin_bit_cast(void*, static_cast<uintptr_t>(-1));62 }63 64 void check_loc_concreteInt() {65 clang_analyzer_dump(__builtin_bit_cast(unsigned, *(reinterpret_cast<int*>(0xdeadbeef))));66 // expected-warning@-1 {{Unknown}}67 }68}69