[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Analysis / bug_hash_test.cpp
blob7b812a76558dd268322c47a0f1cefefee4df2f66
1 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.ExprInspection %s -verify
3 constexpr int clang_analyzer_hashDump(int) { return 5; }
5 void function(int) {
6 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void function(int)$27$clang_analyzer_hashDump(5);$Category}}
9 namespace {
10 void variadicParam(int, ...) {
11 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void (anonymous namespace)::variadicParam(int, ...)$27$clang_analyzer_hashDump(5);$Category}}
13 } // namespace
15 constexpr int f() {
16 return clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$int f()$34$returnclang_analyzer_hashDump(5);$Category}}
19 namespace AA {
20 class X {
21 X() {
22 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::X()$29$clang_analyzer_hashDump(5);$Category}}
25 static void static_method() {
26 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::static_method()$29$clang_analyzer_hashDump(5);$Category}}
27 variadicParam(5);
30 void method() && {
31 struct Y {
32 inline void method() const & {
33 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::method()::Y::method() const &$33$clang_analyzer_hashDump(5);$Category}}
37 Y y;
38 y.method();
40 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::method() &&$29$clang_analyzer_hashDump(5);$Category}}
43 void OutOfLine();
45 X &operator=(int) {
46 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$X & AA::X::operator=(int)$29$clang_analyzer_hashDump(5);$Category}}
47 return *this;
50 operator int() {
51 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::operator int()$29$clang_analyzer_hashDump(5);$Category}}
52 return 0;
55 explicit operator float() {
56 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::operator float()$29$clang_analyzer_hashDump(5);$Category}}
57 return 0;
60 } // namespace AA
62 void AA::X::OutOfLine() {
63 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::OutOfLine()$27$clang_analyzer_hashDump(5);$Category}}
66 void testLambda() {
67 []() {
68 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void testLambda()::(anonymous class)::operator()() const$29$clang_analyzer_hashDump(5);$Category}}
69 }();
72 template <typename T>
73 void f(T) {
74 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(T)$27$clang_analyzer_hashDump(5);$Category}}
77 template <typename T>
78 struct TX {
79 void f(T) {
80 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX::f(T)$29$clang_analyzer_hashDump(5);$Category}}
84 template <>
85 void f<long>(long) {
86 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(long)$27$clang_analyzer_hashDump(5);$Category}}
89 template <>
90 struct TX<long> {
91 void f(long) {
92 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX<long>::f(long)$29$clang_analyzer_hashDump(5);$Category}}
96 template <typename T>
97 struct TTX {
98 template<typename S>
99 void f(T, S) {
100 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TTX::f(T, S)$29$clang_analyzer_hashDump(5);$Category}}
104 void g() {
105 // TX<int> and TX<double> is instantiated from the same code with the same
106 // source locations. The same error happining in both of the instantiations
107 // should share the common hash. This means we should not include the
108 // template argument for these types in the function signature.
109 // Note that, we still want the hash to be different for explicit
110 // specializations.
111 TX<int> x;
112 TX<double> y;
113 TX<long> xl;
114 x.f(1);
115 xl.f(1);
116 f(5);
117 f(3.0);
118 y.f(2);
119 TTX<int> z;
120 z.f<int>(5, 5);
121 f(5l);