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