Commit Graph

11 Commits

Author SHA1 Message Date
Jordan Rose 5772f82d1e [analyzer] Make sure a materialized temporary matches its bindings.
This is a follow-up to r175830, which made sure a temporary object region
created for, say, a struct rvalue matched up with the initial bindings
being stored into it. This does the same for the case in which the AST
actually tells us that we need to create a temporary via a
MaterializeObjectExpr. I've unified the two code paths and moved a static
helper function onto ExprEngine.

This also caused a bit of test churn, causing us to go back to describing
temporary regions without a 'const' qualifier. This seems acceptable; it's
our behavior from a few months ago.

<rdar://problem/13265460> (part 2)

llvm-svn: 175854
2013-02-22 01:51:15 +00:00
Ted Kremenek a3bb2b6044 Fix regression in modeling assignments of an address of a variable to itself. Fixes <rdar://problem/13226577>.
llvm-svn: 175852
2013-02-22 01:39:26 +00:00
Hans Wennborg d799a2b3b9 Better wording for reference self-initialization warning.
llvm-svn: 162198
2012-08-20 08:52:22 +00:00
Hans Wennborg e1fdb059c6 Warn about self-initialization of references.
Initializing a reference with itself, e.g. "int &a = a;" seems like a
very bad idea.

llvm-svn: 162093
2012-08-17 10:12:33 +00:00
Argyrios Kyrtzidis b4015e1877 When going through references to check if the function returns the address
of a local variable, make sure we don't infinitely recurse when the
reference binds to itself.

e.g:

int* func() {
    int& i = i;    // assign non-exist variable to a reference which has same name.
    return &i;    // return pointer
}

rdar://11345441

llvm-svn: 155856
2012-04-30 23:23:55 +00:00
Ted Kremenek 2a14c695eb Fix LiveVariables analysis bug with MaterializeTemporaryExpr and fix handling in ExprEngine. Fixes <rdar://problem/10201666>.
llvm-svn: 140956
2011-10-02 00:54:48 +00:00
Jeffrey Yasskin 0e9cdbbb06 Handle CXXTempObjectRegion in StackAddrEscapeChecker.
Also convert stack-addr-ps.cpp to use the analyzer instead of just Sema, now
that it doesn't crash, and extract the stack-block test into another file since
it errors, and that prevents the analyzer from running.

llvm-svn: 138613
2011-08-26 00:41:31 +00:00
Argyrios Kyrtzidis e72f7154f1 Follow through references to catch returned stack addresses, local blocks, label addresses or references to temporaries, e.g:
const int& g2() {
  int s1;
  int &s2 = s1; // expected-note {{binding reference variable 's2' here}}
  return s2; // expected-warning {{reference to stack memory associated with local variable 's1' returned}}
}

llvm-svn: 120483
2010-11-30 22:57:32 +00:00
Argyrios Kyrtzidis 091d97c709 Revert r120331 since it causes spurious warnings and a possible assertion hit when self-host.
llvm-svn: 120351
2010-11-29 23:42:03 +00:00
Argyrios Kyrtzidis 569cad9734 Emit warnings if we are returning a reference to a local temporary.
The issue was brought to our attention by Matthieu Monrocq.

llvm-svn: 120331
2010-11-29 22:32:08 +00:00
Ted Kremenek b786156b01 Teach SemaChecking::CheckReturnStackAddr about ImplicitCastExprs that convert values to an lvalue. This allows us to warn (again) about returning references to stack variables. (fixes PR 7812).
llvm-svn: 110242
2010-08-04 20:01:07 +00:00