Re: r336716 - Revert r336590 "[libclang] evalute compound statement cursors before trying to evaluate"

2019-01-08 Thread Alex L via cfe-commits
Fixed in r350680.

On Tue, 8 Jan 2019 at 15:24, Alex L  wrote:

> Looks like there was another leak I missed. I'm working on fixing it now.
> Cheers,
> Alex
>
> On Tue, 8 Jan 2019 at 14:38, Alex L  wrote:
>
>> Thanks for reverting the commit! Unfortunately I missed the failure back
>> then.
>> I fixed the leak and recommitted the change in r350666.
>>
>> Cheers,
>> Alex
>>
>> On Tue, 10 Jul 2018 at 12:53, Evgeniy Stepanov via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: eugenis
>>> Date: Tue Jul 10 12:49:07 2018
>>> New Revision: 336716
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=336716&view=rev
>>> Log:
>>> Revert r336590 "[libclang] evalute compound statement cursors before
>>> trying to evaluate"
>>>
>>> New memory leaks in
>>> LibclangParseTest_EvaluateChildExpression_Test::TestBody()
>>>
>>> Modified:
>>> cfe/trunk/tools/libclang/CIndex.cpp
>>> cfe/trunk/unittests/libclang/LibclangTest.cpp
>>>
>>> Modified: cfe/trunk/tools/libclang/CIndex.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336716&r1=336715&r2=336716&view=diff
>>>
>>> ==
>>> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
>>> +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:49:07 2018
>>> @@ -3890,19 +3890,6 @@ static const ExprEvalResult* evaluateExp
>>>  }
>>>
>>>  CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
>>> -  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
>>> -const CompoundStmt *compoundStmt =
>>> cast(getCursorStmt(C));
>>> -Expr *expr = nullptr;
>>> -for (auto *bodyIterator : compoundStmt->body()) {
>>> -  if ((expr = dyn_cast(bodyIterator))) {
>>> -break;
>>> -  }
>>> -}
>>> -if (expr)
>>> -  return const_cast(
>>> -  reinterpret_cast(evaluateExpr(expr, C)));
>>> -  }
>>> -
>>>const Decl *D = getCursorDecl(C);
>>>if (D) {
>>>  const Expr *expr = nullptr;
>>> @@ -3916,6 +3903,19 @@ CXEvalResult clang_Cursor_Evaluate(CXCur
>>>evaluateExpr(const_cast(expr), C)));
>>>  return nullptr;
>>>}
>>> +
>>> +  const CompoundStmt *compoundStmt =
>>> dyn_cast_or_null(getCursorStmt(C));
>>> +  if (compoundStmt) {
>>> +Expr *expr = nullptr;
>>> +for (auto *bodyIterator : compoundStmt->body()) {
>>> +  if ((expr = dyn_cast(bodyIterator))) {
>>> +break;
>>> +  }
>>> +}
>>> +if (expr)
>>> +  return const_cast(
>>> +  reinterpret_cast(evaluateExpr(expr, C)));
>>> +  }
>>>return nullptr;
>>>  }
>>>
>>>
>>> Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=336716&r1=336715&r2=336716&view=diff
>>>
>>> ==
>>> --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
>>> +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Tue Jul 10 12:49:07
>>> 2018
>>> @@ -461,47 +461,6 @@ TEST_F(LibclangParseTest, AllSkippedRang
>>>clang_disposeSourceRangeList(Ranges);
>>>  }
>>>
>>> -TEST_F(LibclangParseTest, EvaluateChildExpression) {
>>> -  std::string Main = "main.m";
>>> -  WriteFile(Main, "#define kFOO @\"foo\"\n"
>>> -  "void foobar(void) {\n"
>>> -  " {kFOO;}\n"
>>> -  "}\n");
>>> -  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
>>> nullptr,
>>> -   0, TUFlags);
>>> -
>>> -  CXCursor C = clang_getTranslationUnitCursor(ClangTU);
>>> -  clang_visitChildren(
>>> -  C,
>>> -  [](CXCursor cursor, CXCursor parent,
>>> - CXClientData client_data) -> CXChildVisitResult {
>>> -if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
>>> -  int numberedStmt = 0;
>>> -  clang_visitChildren(

Re: r336716 - Revert r336590 "[libclang] evalute compound statement cursors before trying to evaluate"

2019-01-08 Thread Alex L via cfe-commits
Looks like there was another leak I missed. I'm working on fixing it now.
Cheers,
Alex

On Tue, 8 Jan 2019 at 14:38, Alex L  wrote:

> Thanks for reverting the commit! Unfortunately I missed the failure back
> then.
> I fixed the leak and recommitted the change in r350666.
>
> Cheers,
> Alex
>
> On Tue, 10 Jul 2018 at 12:53, Evgeniy Stepanov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: eugenis
>> Date: Tue Jul 10 12:49:07 2018
>> New Revision: 336716
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=336716&view=rev
>> Log:
>> Revert r336590 "[libclang] evalute compound statement cursors before
>> trying to evaluate"
>>
>> New memory leaks in
>> LibclangParseTest_EvaluateChildExpression_Test::TestBody()
>>
>> Modified:
>> cfe/trunk/tools/libclang/CIndex.cpp
>> cfe/trunk/unittests/libclang/LibclangTest.cpp
>>
>> Modified: cfe/trunk/tools/libclang/CIndex.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336716&r1=336715&r2=336716&view=diff
>>
>> ==
>> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
>> +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:49:07 2018
>> @@ -3890,19 +3890,6 @@ static const ExprEvalResult* evaluateExp
>>  }
>>
>>  CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
>> -  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
>> -const CompoundStmt *compoundStmt =
>> cast(getCursorStmt(C));
>> -Expr *expr = nullptr;
>> -for (auto *bodyIterator : compoundStmt->body()) {
>> -  if ((expr = dyn_cast(bodyIterator))) {
>> -break;
>> -  }
>> -}
>> -if (expr)
>> -  return const_cast(
>> -  reinterpret_cast(evaluateExpr(expr, C)));
>> -  }
>> -
>>const Decl *D = getCursorDecl(C);
>>if (D) {
>>  const Expr *expr = nullptr;
>> @@ -3916,6 +3903,19 @@ CXEvalResult clang_Cursor_Evaluate(CXCur
>>evaluateExpr(const_cast(expr), C)));
>>  return nullptr;
>>}
>> +
>> +  const CompoundStmt *compoundStmt =
>> dyn_cast_or_null(getCursorStmt(C));
>> +  if (compoundStmt) {
>> +Expr *expr = nullptr;
>> +for (auto *bodyIterator : compoundStmt->body()) {
>> +  if ((expr = dyn_cast(bodyIterator))) {
>> +break;
>> +  }
>> +}
>> +if (expr)
>> +  return const_cast(
>> +  reinterpret_cast(evaluateExpr(expr, C)));
>> +  }
>>return nullptr;
>>  }
>>
>>
>> Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=336716&r1=336715&r2=336716&view=diff
>>
>> ==
>> --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
>> +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Tue Jul 10 12:49:07 2018
>> @@ -461,47 +461,6 @@ TEST_F(LibclangParseTest, AllSkippedRang
>>clang_disposeSourceRangeList(Ranges);
>>  }
>>
>> -TEST_F(LibclangParseTest, EvaluateChildExpression) {
>> -  std::string Main = "main.m";
>> -  WriteFile(Main, "#define kFOO @\"foo\"\n"
>> -  "void foobar(void) {\n"
>> -  " {kFOO;}\n"
>> -  "}\n");
>> -  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
>> nullptr,
>> -   0, TUFlags);
>> -
>> -  CXCursor C = clang_getTranslationUnitCursor(ClangTU);
>> -  clang_visitChildren(
>> -  C,
>> -  [](CXCursor cursor, CXCursor parent,
>> - CXClientData client_data) -> CXChildVisitResult {
>> -if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
>> -  int numberedStmt = 0;
>> -  clang_visitChildren(
>> -  cursor,
>> -  [](CXCursor cursor, CXCursor parent,
>> - CXClientData client_data) -> CXChildVisitResult {
>> -int &numberedStmt = *((int *)client_data);
>> -if (clang_getCursorKind(cursor) ==
>> CXCursor_CompoundStmt) {
>> -  if (numberedStmt) {
>> -CXEvalResult RE = clang_Cursor_Evaluate(cursor);
>> -EXPECT_NE(RE, nullptr);
>&

Re: r336716 - Revert r336590 "[libclang] evalute compound statement cursors before trying to evaluate"

2019-01-08 Thread Alex L via cfe-commits
Thanks for reverting the commit! Unfortunately I missed the failure back
then.
I fixed the leak and recommitted the change in r350666.

Cheers,
Alex

On Tue, 10 Jul 2018 at 12:53, Evgeniy Stepanov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: eugenis
> Date: Tue Jul 10 12:49:07 2018
> New Revision: 336716
>
> URL: http://llvm.org/viewvc/llvm-project?rev=336716&view=rev
> Log:
> Revert r336590 "[libclang] evalute compound statement cursors before
> trying to evaluate"
>
> New memory leaks in
> LibclangParseTest_EvaluateChildExpression_Test::TestBody()
>
> Modified:
> cfe/trunk/tools/libclang/CIndex.cpp
> cfe/trunk/unittests/libclang/LibclangTest.cpp
>
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336716&r1=336715&r2=336716&view=diff
>
> ==
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:49:07 2018
> @@ -3890,19 +3890,6 @@ static const ExprEvalResult* evaluateExp
>  }
>
>  CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
> -  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
> -const CompoundStmt *compoundStmt =
> cast(getCursorStmt(C));
> -Expr *expr = nullptr;
> -for (auto *bodyIterator : compoundStmt->body()) {
> -  if ((expr = dyn_cast(bodyIterator))) {
> -break;
> -  }
> -}
> -if (expr)
> -  return const_cast(
> -  reinterpret_cast(evaluateExpr(expr, C)));
> -  }
> -
>const Decl *D = getCursorDecl(C);
>if (D) {
>  const Expr *expr = nullptr;
> @@ -3916,6 +3903,19 @@ CXEvalResult clang_Cursor_Evaluate(CXCur
>evaluateExpr(const_cast(expr), C)));
>  return nullptr;
>}
> +
> +  const CompoundStmt *compoundStmt =
> dyn_cast_or_null(getCursorStmt(C));
> +  if (compoundStmt) {
> +Expr *expr = nullptr;
> +for (auto *bodyIterator : compoundStmt->body()) {
> +  if ((expr = dyn_cast(bodyIterator))) {
> +break;
> +  }
> +}
> +if (expr)
> +  return const_cast(
> +  reinterpret_cast(evaluateExpr(expr, C)));
> +  }
>return nullptr;
>  }
>
>
> Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=336716&r1=336715&r2=336716&view=diff
>
> ==
> --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
> +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Tue Jul 10 12:49:07 2018
> @@ -461,47 +461,6 @@ TEST_F(LibclangParseTest, AllSkippedRang
>clang_disposeSourceRangeList(Ranges);
>  }
>
> -TEST_F(LibclangParseTest, EvaluateChildExpression) {
> -  std::string Main = "main.m";
> -  WriteFile(Main, "#define kFOO @\"foo\"\n"
> -  "void foobar(void) {\n"
> -  " {kFOO;}\n"
> -  "}\n");
> -  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
> nullptr,
> -   0, TUFlags);
> -
> -  CXCursor C = clang_getTranslationUnitCursor(ClangTU);
> -  clang_visitChildren(
> -  C,
> -  [](CXCursor cursor, CXCursor parent,
> - CXClientData client_data) -> CXChildVisitResult {
> -if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
> -  int numberedStmt = 0;
> -  clang_visitChildren(
> -  cursor,
> -  [](CXCursor cursor, CXCursor parent,
> - CXClientData client_data) -> CXChildVisitResult {
> -int &numberedStmt = *((int *)client_data);
> -if (clang_getCursorKind(cursor) == CXCursor_CompoundStmt)
> {
> -  if (numberedStmt) {
> -CXEvalResult RE = clang_Cursor_Evaluate(cursor);
> -EXPECT_NE(RE, nullptr);
> -EXPECT_EQ(clang_EvalResult_getKind(RE),
> -  CXEval_ObjCStrLiteral);
> -return CXChildVisit_Break;
> -  }
> -  numberedStmt++;
> -}
> -return CXChildVisit_Recurse;
> -  },
> -  &numberedStmt);
> -  EXPECT_EQ(numberedStmt, 1);
> -}
> -return CXChildVisit_Continue;
> -  },
> -  nullptr);
> -}
> -
>  class LibclangReparseTest : public LibclangParseTest {
>  public:
>void DisplayDiagnostics() {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r336716 - Revert r336590 "[libclang] evalute compound statement cursors before trying to evaluate"

2018-07-10 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Tue Jul 10 12:49:07 2018
New Revision: 336716

URL: http://llvm.org/viewvc/llvm-project?rev=336716&view=rev
Log:
Revert r336590 "[libclang] evalute compound statement cursors before trying to 
evaluate"

New memory leaks in
LibclangParseTest_EvaluateChildExpression_Test::TestBody()

Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336716&r1=336715&r2=336716&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:49:07 2018
@@ -3890,19 +3890,6 @@ static const ExprEvalResult* evaluateExp
 }
 
 CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
-  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
-const CompoundStmt *compoundStmt = cast(getCursorStmt(C));
-Expr *expr = nullptr;
-for (auto *bodyIterator : compoundStmt->body()) {
-  if ((expr = dyn_cast(bodyIterator))) {
-break;
-  }
-}
-if (expr)
-  return const_cast(
-  reinterpret_cast(evaluateExpr(expr, C)));
-  }
-
   const Decl *D = getCursorDecl(C);
   if (D) {
 const Expr *expr = nullptr;
@@ -3916,6 +3903,19 @@ CXEvalResult clang_Cursor_Evaluate(CXCur
   evaluateExpr(const_cast(expr), C)));
 return nullptr;
   }
+
+  const CompoundStmt *compoundStmt = 
dyn_cast_or_null(getCursorStmt(C));
+  if (compoundStmt) {
+Expr *expr = nullptr;
+for (auto *bodyIterator : compoundStmt->body()) {
+  if ((expr = dyn_cast(bodyIterator))) {
+break;
+  }
+}
+if (expr)
+  return const_cast(
+  reinterpret_cast(evaluateExpr(expr, C)));
+  }
   return nullptr;
 }
 

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=336716&r1=336715&r2=336716&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Tue Jul 10 12:49:07 2018
@@ -461,47 +461,6 @@ TEST_F(LibclangParseTest, AllSkippedRang
   clang_disposeSourceRangeList(Ranges);
 }
 
-TEST_F(LibclangParseTest, EvaluateChildExpression) {
-  std::string Main = "main.m";
-  WriteFile(Main, "#define kFOO @\"foo\"\n"
-  "void foobar(void) {\n"
-  " {kFOO;}\n"
-  "}\n");
-  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, 
nullptr,
-   0, TUFlags);
-
-  CXCursor C = clang_getTranslationUnitCursor(ClangTU);
-  clang_visitChildren(
-  C,
-  [](CXCursor cursor, CXCursor parent,
- CXClientData client_data) -> CXChildVisitResult {
-if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
-  int numberedStmt = 0;
-  clang_visitChildren(
-  cursor,
-  [](CXCursor cursor, CXCursor parent,
- CXClientData client_data) -> CXChildVisitResult {
-int &numberedStmt = *((int *)client_data);
-if (clang_getCursorKind(cursor) == CXCursor_CompoundStmt) {
-  if (numberedStmt) {
-CXEvalResult RE = clang_Cursor_Evaluate(cursor);
-EXPECT_NE(RE, nullptr);
-EXPECT_EQ(clang_EvalResult_getKind(RE),
-  CXEval_ObjCStrLiteral);
-return CXChildVisit_Break;
-  }
-  numberedStmt++;
-}
-return CXChildVisit_Recurse;
-  },
-  &numberedStmt);
-  EXPECT_EQ(numberedStmt, 1);
-}
-return CXChildVisit_Continue;
-  },
-  nullptr);
-}
-
 class LibclangReparseTest : public LibclangParseTest {
 public:
   void DisplayDiagnostics() {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r336590 - [libclang] evalute compound statement cursors before trying to evaluate

2018-07-10 Thread Evgenii Stepanov via cfe-commits
Reverting...

On Mon, Jul 9, 2018 at 8:18 PM, Vlad Tsyrklevich  wrote:
> The ASan bot is failing with a LeakSanitizer failure that appears related to
> one of your libclang changes:
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/6282/steps/check-clang%20asan/logs/stdio
>
> Direct leak of 24 byte(s) in 1 object(s) allocated from:
> #0 0x52c638 in operator new(unsigned long)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:106
> #1 0x7fd236783b89 in make_unique
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/ADT/STLExtras.h:1057:29
> #2 0x7fd236783b89 in evaluateExpr
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3755
> #3 0x7fd236783b89 in clang_Cursor_Evaluate
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3917
> #4 0x54e743 in operator()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:487:39
> #5 0x54e743 in
> LibclangParseTest_EvaluateChildExpression_Test::TestBody()::$_0::operator()(CXCursor,
> CXCursor, void*) const::'lambda'(CXCursor, CXCursor,
> void*)::__invoke(CXCursor, CXCursor, void*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:482
> #6 0x7fd23677de00 in
> clang::cxcursor::CursorVisitor::RunVisitorWorkList(llvm::SmallVector 10u>&)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3019:17
> #7 0x7fd23675c3a8 in clang::cxcursor::CursorVisitor::Visit(clang::Stmt
> const*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3164:17
> #8 0x7fd236755d2f in
> clang::cxcursor::CursorVisitor::VisitChildren(CXCursor)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp
> #9 0x7fd236754e5d in clang::cxcursor::CursorVisitor::Visit(CXCursor,
> bool)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:225:16
> #10 0x7fd23676487c in
> clang::cxcursor::CursorVisitor::VisitFunctionDecl(clang::FunctionDecl*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:889:9
> #11 0x7fd236759e24 in
> clang::declvisitor::Base clang::cxcursor::CursorVisitor, bool>::Visit(clang::Decl*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/include/clang/AST/DeclVisitor.h
> #12 0x7fd236755c17 in
> clang::cxcursor::CursorVisitor::VisitChildren(CXCursor)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:506:34
> #13 0x7fd23678a558 in clang_visitChildren
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:4352:20
> #14 0x54e024 in operator()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:480:11
> #15 0x54e024 in
> LibclangParseTest_EvaluateChildExpression_Test::TestBody()::$_0::__invoke(CXCursor,
> CXCursor, void*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:476
> #16 0x7fd236754d49 in clang::cxcursor::CursorVisitor::Visit(CXCursor,
> bool)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:217:11
> #17 0x7fd23675cb87 in
> clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl const*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:674:7
> #18 0x7fd23675cefe in
> clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:635:30
> #19 0x7fd236756399 in
> clang::cxcursor::CursorVisitor::VisitChildren(CXCursor)
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:540:20
> #20 0x7fd23678a558 in clang_visitChildren
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:4352:20
> #21 0x537fa1 in
> LibclangParseTest_EvaluateChildExpression_Test::TestBody()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:474:3
> #22 0x5cae31 in testing::Test::Run()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc
> #23 0x5cd068 in testing::TestInfo::Run()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11
> #24 0x5ce430 in testing::TestCase::Run()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28
> #25 0x5ec1d4 in testing::internal::UnitTestImpl::RunAllTests()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43
> #26 0x5eb380 in testing::UnitTest::Run()
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc
> #27 0x5b3983 in RUN

Re: r336590 - [libclang] evalute compound statement cursors before trying to evaluate

2018-07-09 Thread Vlad Tsyrklevich via cfe-commits
The ASan bot is failing with a LeakSanitizer failure that appears related
to one of your libclang changes:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/6282/steps/check-clang%20asan/logs/stdio

Direct leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x52c638 in operator new(unsigned long)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:106
#1 0x7fd236783b89 in make_unique
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/ADT/STLExtras.h:1057:29
#2 0x7fd236783b89 in evaluateExpr
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3755
#3 0x7fd236783b89 in clang_Cursor_Evaluate
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3917
#4 0x54e743 in operator()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:487:39
#5 0x54e743 in
LibclangParseTest_EvaluateChildExpression_Test::TestBody()::$_0::operator()(CXCursor,
CXCursor, void*) const::'lambda'(CXCursor, CXCursor,
void*)::__invoke(CXCursor, CXCursor, void*)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:482
#6 0x7fd23677de00 in
clang::cxcursor::CursorVisitor::RunVisitorWorkList(llvm::SmallVector&) 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3019:17
#7 0x7fd23675c3a8 in
clang::cxcursor::CursorVisitor::Visit(clang::Stmt const*)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3164:17
#8 0x7fd236755d2f in
clang::cxcursor::CursorVisitor::VisitChildren(CXCursor)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp
#9 0x7fd236754e5d in
clang::cxcursor::CursorVisitor::Visit(CXCursor, bool)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:225:16
#10 0x7fd23676487c in
clang::cxcursor::CursorVisitor::VisitFunctionDecl(clang::FunctionDecl*)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:889:9
#11 0x7fd236759e24 in
clang::declvisitor::Base::Visit(clang::Decl*)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/include/clang/AST/DeclVisitor.h
#12 0x7fd236755c17 in
clang::cxcursor::CursorVisitor::VisitChildren(CXCursor)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:506:34
#13 0x7fd23678a558 in clang_visitChildren
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:4352:20
#14 0x54e024 in operator()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:480:11
#15 0x54e024 in
LibclangParseTest_EvaluateChildExpression_Test::TestBody()::$_0::__invoke(CXCursor,
CXCursor, void*)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:476
#16 0x7fd236754d49 in
clang::cxcursor::CursorVisitor::Visit(CXCursor, bool)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:217:11
#17 0x7fd23675cb87 in
clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl
const*) 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:674:7
#18 0x7fd23675cefe in
clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:635:30
#19 0x7fd236756399 in
clang::cxcursor::CursorVisitor::VisitChildren(CXCursor)
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:540:20
#20 0x7fd23678a558 in clang_visitChildren
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:4352:20
#21 0x537fa1 in
LibclangParseTest_EvaluateChildExpression_Test::TestBody()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:474:3
#22 0x5cae31 in testing::Test::Run()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc
#23 0x5cd068 in testing::TestInfo::Run()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11
#24 0x5ce430 in testing::TestCase::Run()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28
#25 0x5ec1d4 in testing::internal::UnitTestImpl::RunAllTests()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43
   #26 0x5eb380 in testing::UnitTest::Run()
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc
#27 0x5b3983 in RUN_ALL_TESTS
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46
#28 0x5b3983 in main
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:51
#29 0x7fd232efd2e0 in __libc_sta

r336590 - [libclang] evalute compound statement cursors before trying to evaluate

2018-07-09 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Jul  9 12:41:28 2018
New Revision: 336590

URL: http://llvm.org/viewvc/llvm-project?rev=336590&view=rev
Log:
[libclang] evalute compound statement cursors before trying to evaluate
the cursor like a declaration

This change fixes a bug in libclang in which it tries to evaluate a statement
cursor as a declaration cursor, because that statement still has a pointer to
the declaration parent.

rdar://3477

Differential Revision: https://reviews.llvm.org/D49051

Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=336590&r1=336589&r2=336590&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Jul  9 12:41:28 2018
@@ -3890,6 +3890,19 @@ static const ExprEvalResult* evaluateExp
 }
 
 CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
+  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
+const CompoundStmt *compoundStmt = cast(getCursorStmt(C));
+Expr *expr = nullptr;
+for (auto *bodyIterator : compoundStmt->body()) {
+  if ((expr = dyn_cast(bodyIterator))) {
+break;
+  }
+}
+if (expr)
+  return const_cast(
+  reinterpret_cast(evaluateExpr(expr, C)));
+  }
+
   const Decl *D = getCursorDecl(C);
   if (D) {
 const Expr *expr = nullptr;
@@ -3903,19 +3916,6 @@ CXEvalResult clang_Cursor_Evaluate(CXCur
   evaluateExpr(const_cast(expr), C)));
 return nullptr;
   }
-
-  const CompoundStmt *compoundStmt = 
dyn_cast_or_null(getCursorStmt(C));
-  if (compoundStmt) {
-Expr *expr = nullptr;
-for (auto *bodyIterator : compoundStmt->body()) {
-  if ((expr = dyn_cast(bodyIterator))) {
-break;
-  }
-}
-if (expr)
-  return const_cast(
-  reinterpret_cast(evaluateExpr(expr, C)));
-  }
   return nullptr;
 }
 

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=336590&r1=336589&r2=336590&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Mon Jul  9 12:41:28 2018
@@ -461,6 +461,47 @@ TEST_F(LibclangParseTest, AllSkippedRang
   clang_disposeSourceRangeList(Ranges);
 }
 
+TEST_F(LibclangParseTest, EvaluateChildExpression) {
+  std::string Main = "main.m";
+  WriteFile(Main, "#define kFOO @\"foo\"\n"
+  "void foobar(void) {\n"
+  " {kFOO;}\n"
+  "}\n");
+  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, 
nullptr,
+   0, TUFlags);
+
+  CXCursor C = clang_getTranslationUnitCursor(ClangTU);
+  clang_visitChildren(
+  C,
+  [](CXCursor cursor, CXCursor parent,
+ CXClientData client_data) -> CXChildVisitResult {
+if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
+  int numberedStmt = 0;
+  clang_visitChildren(
+  cursor,
+  [](CXCursor cursor, CXCursor parent,
+ CXClientData client_data) -> CXChildVisitResult {
+int &numberedStmt = *((int *)client_data);
+if (clang_getCursorKind(cursor) == CXCursor_CompoundStmt) {
+  if (numberedStmt) {
+CXEvalResult RE = clang_Cursor_Evaluate(cursor);
+EXPECT_NE(RE, nullptr);
+EXPECT_EQ(clang_EvalResult_getKind(RE),
+  CXEval_ObjCStrLiteral);
+return CXChildVisit_Break;
+  }
+  numberedStmt++;
+}
+return CXChildVisit_Recurse;
+  },
+  &numberedStmt);
+  EXPECT_EQ(numberedStmt, 1);
+}
+return CXChildVisit_Continue;
+  },
+  nullptr);
+}
+
 class LibclangReparseTest : public LibclangParseTest {
 public:
   void DisplayDiagnostics() {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits