From: Zhongxing Xu Date: Sat, 19 Dec 2009 03:17:55 +0000 (+0000) Subject: Use the FunctionDecl's result type to know exactly if it returns a reference. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=910e4080986045cc2036f8d1f55398acc7fbb257;p=clang Use the FunctionDecl's result type to know exactly if it returns a reference. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91751 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index cc73841b78..fb253a3c8f 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -2942,6 +2942,16 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst, QualType T = Ex->getType(); + // For CallExpr, use the result type to know if it returns a reference. + if (const CallExpr *CE = dyn_cast(Ex)) { + const Expr *Callee = CE->getCallee(); + SVal L = state->getSVal(Callee); + + const FunctionDecl *FD = L.getAsFunctionDecl(); + if (FD) + T = FD->getResultType(); + } + if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) { unsigned Count = Builder.getCurrentBlockCount(); ValueManager &ValMgr = Eng.getValueManager(); diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index 838ac39d5c..c3e07b26b0 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/test/Analysis/misc-ps-region-store.cpp @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -// XFAIL: * // Test basic handling of references. char &test1_aux(); @@ -8,7 +7,7 @@ char *test1() { return &test1_aux(); } -// This test currently crasehs because test1_aux() evaluates to a 'char' instead of a char& in CFRefCount.cpp. +// Test test1_aux() evaluates to char &. char test1_as_rvalue() { return test1_aux(); }