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