Index: clang/lib/Analysis/UnsafeBufferUsage.cpp =================================================================== --- clang/lib/Analysis/UnsafeBufferUsage.cpp +++ clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -1106,7 +1106,7 @@ // In parallel, match all DeclRefExprs so that to find out // whether there are any uncovered by gadgets. declRefExpr(anyOf(hasPointerType(), hasArrayType()), - to(varDecl())).bind("any_dre"), + to(anyOf(varDecl(), bindingDecl()))).bind("any_dre"), // Also match DeclStmts because we'll need them when fixing // their underlying VarDecls that otherwise don't have // any backreferences to DeclStmts. Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp =================================================================== --- clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp +++ clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp @@ -78,3 +78,22 @@ auto [x, y] = a; x = 9; } + +void test_claim_use_multiple() { + int *a = new int[8]; // expected-warning{{'a' is an unsafe pointer used for buffer access}} + a[6] = 9; // expected-note{{used in buffer access here}} + a++; // expected-note{{used in pointer arithmetic here}} \ + // debug-note{{safe buffers debug: failed to produce fixit for 'a' : has an unclaimed use}} +} + +struct S +{ + int *x; +}; + +S f() { return S{new int[4]}; } + +void test_struct_claim_use() { + auto [x] = f(); + x[6] = 8; // expected-warning{{unsafe buffer access}} +}