1f4a2713aSLionel Sambuc //===- unittests/AST/DeclTest.cpp --- Declaration tests -------------------===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // Unit tests for Decl nodes in the AST. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuc #include "clang/ASTMatchers/ASTMatchFinder.h" 15f4a2713aSLionel Sambuc #include "clang/Tooling/Tooling.h" 16f4a2713aSLionel Sambuc #include "gtest/gtest.h" 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuc using namespace clang::ast_matchers; 19f4a2713aSLionel Sambuc using namespace clang::tooling; 20f4a2713aSLionel Sambuc TEST(Decl,CleansUpAPValues)21f4a2713aSLionel SambucTEST(Decl, CleansUpAPValues) { 22f4a2713aSLionel Sambuc MatchFinder Finder; 23*0a6a1f1dSLionel Sambuc std::unique_ptr<FrontendActionFactory> Factory( 24f4a2713aSLionel Sambuc newFrontendActionFactory(&Finder)); 25f4a2713aSLionel Sambuc 26f4a2713aSLionel Sambuc // This is a regression test for a memory leak in APValues for structs that 27f4a2713aSLionel Sambuc // allocate memory. This test only fails if run under valgrind with full leak 28f4a2713aSLionel Sambuc // checking enabled. 29f4a2713aSLionel Sambuc std::vector<std::string> Args(1, "-std=c++11"); 30f4a2713aSLionel Sambuc Args.push_back("-fno-ms-extensions"); 31f4a2713aSLionel Sambuc ASSERT_TRUE(runToolOnCodeWithArgs( 32f4a2713aSLionel Sambuc Factory->create(), 33f4a2713aSLionel Sambuc "struct X { int a; }; constexpr X x = { 42 };" 34f4a2713aSLionel Sambuc "union Y { constexpr Y(int a) : a(a) {} int a; }; constexpr Y y = { 42 };" 35f4a2713aSLionel Sambuc "constexpr int z[2] = { 42, 43 };" 36f4a2713aSLionel Sambuc "constexpr int __attribute__((vector_size(16))) v1 = {};" 37f4a2713aSLionel Sambuc "\n#ifdef __SIZEOF_INT128__\n" 38f4a2713aSLionel Sambuc "constexpr __uint128_t large_int = 0xffffffffffffffff;" 39f4a2713aSLionel Sambuc "constexpr __uint128_t small_int = 1;" 40f4a2713aSLionel Sambuc "\n#endif\n" 41f4a2713aSLionel Sambuc "constexpr double d1 = 42.42;" 42f4a2713aSLionel Sambuc "constexpr long double d2 = 42.42;" 43f4a2713aSLionel Sambuc "constexpr _Complex long double c1 = 42.0i;" 44f4a2713aSLionel Sambuc "constexpr _Complex long double c2 = 42.0;" 45f4a2713aSLionel Sambuc "template<int N> struct A : A<N-1> {};" 46f4a2713aSLionel Sambuc "template<> struct A<0> { int n; }; A<50> a;" 47f4a2713aSLionel Sambuc "constexpr int &r = a.n;" 48f4a2713aSLionel Sambuc "constexpr int A<50>::*p = &A<50>::n;" 49f4a2713aSLionel Sambuc "void f() { foo: bar: constexpr int k = __builtin_constant_p(0) ?" 50f4a2713aSLionel Sambuc " (char*)&&foo - (char*)&&bar : 0; }", 51f4a2713aSLionel Sambuc Args)); 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc // FIXME: Once this test starts breaking we can test APValue::needsCleanup 54f4a2713aSLionel Sambuc // for ComplexInt. 55f4a2713aSLionel Sambuc ASSERT_FALSE(runToolOnCodeWithArgs( 56f4a2713aSLionel Sambuc Factory->create(), 57f4a2713aSLionel Sambuc "constexpr _Complex __uint128_t c = 0xffffffffffffffff;", 58f4a2713aSLionel Sambuc Args)); 59f4a2713aSLionel Sambuc } 60