diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2012-07-31 16:34:07 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2012-07-31 16:34:07 +0000 |
| commit | e8a21b73ac5b4d84981fc813db9d8254a45ae477 (patch) | |
| tree | 0c0ce62049db14cafe4a002ab302b3fe98535002 /clang/test/Analysis/reference.cpp | |
| parent | 7b2f36e96aa784d68c9e1f9f12f85ca741c4513a (diff) | |
| download | bcm5719-llvm-e8a21b73ac5b4d84981fc813db9d8254a45ae477.tar.gz bcm5719-llvm-e8a21b73ac5b4d84981fc813db9d8254a45ae477.zip | |
[analyzer] Getting an lvalue for a reference field still requires a load.
This was causing a crash in our array-to-pointer logic, since the region
was clearly not an array.
PR13440 / <rdar://problem/11977113>
llvm-svn: 161051
Diffstat (limited to 'clang/test/Analysis/reference.cpp')
| -rw-r--r-- | clang/test/Analysis/reference.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/clang/test/Analysis/reference.cpp b/clang/test/Analysis/reference.cpp index e80952b8228..a12e0bd41cd 100644 --- a/clang/test/Analysis/reference.cpp +++ b/clang/test/Analysis/reference.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-store=region -analyzer-constraints=range -verify -Wno-null-dereference %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,debug.ExprInspection -analyzer-store=region -analyzer-constraints=range -verify -Wno-null-dereference %s + +void clang_analyzer_eval(bool); typedef typeof(sizeof(int)) size_t; void malloc (size_t); @@ -55,3 +57,36 @@ char t6 (char* p) { if (*p) return *p; return *(char*)0; // no-warning } + + +// PR13440 / <rdar://problem/11977113> +// Test that the array-to-pointer decay works for array references as well. +// More generally, when we want an lvalue for a reference field, we still need +// to do one level of load. +namespace PR13440 { + typedef int T[1]; + struct S { + T &x; + + int *m() { return x; } + }; + + struct S2 { + int (&x)[1]; + + int *m() { return x; } + }; + + void test() { + int a[1]; + S s = { a }; + S2 s2 = { a }; + + if (s.x != a) return; + if (s2.x != a) return; + + a[0] = 42; + clang_analyzer_eval(s.x[0] == 42); // expected-warning{{TRUE}} + clang_analyzer_eval(s2.x[0] == 42); // expected-warning{{TRUE}} + } +} |

