2013-06-03 21:51:33 +08:00
|
|
|
//===- unittests/AST/DeclTest.cpp --- Declaration tests -------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-06-03 21:51:33 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Unit tests for Decl nodes in the AST.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace clang::ast_matchers;
|
|
|
|
using namespace clang::tooling;
|
|
|
|
|
|
|
|
TEST(Decl, CleansUpAPValues) {
|
|
|
|
MatchFinder Finder;
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<FrontendActionFactory> Factory(
|
2013-06-03 21:51:33 +08:00
|
|
|
newFrontendActionFactory(&Finder));
|
|
|
|
|
|
|
|
// This is a regression test for a memory leak in APValues for structs that
|
|
|
|
// allocate memory. This test only fails if run under valgrind with full leak
|
|
|
|
// checking enabled.
|
2017-08-09 07:17:51 +08:00
|
|
|
std::vector<std::string> Args(1, "-std=c++11");
|
2013-06-05 14:54:06 +08:00
|
|
|
Args.push_back("-fno-ms-extensions");
|
2013-06-03 21:51:33 +08:00
|
|
|
ASSERT_TRUE(runToolOnCodeWithArgs(
|
|
|
|
Factory->create(),
|
|
|
|
"struct X { int a; }; constexpr X x = { 42 };"
|
|
|
|
"union Y { constexpr Y(int a) : a(a) {} int a; }; constexpr Y y = { 42 };"
|
|
|
|
"constexpr int z[2] = { 42, 43 };"
|
|
|
|
"constexpr int __attribute__((vector_size(16))) v1 = {};"
|
2013-06-04 03:37:18 +08:00
|
|
|
"\n#ifdef __SIZEOF_INT128__\n"
|
2013-06-03 21:51:33 +08:00
|
|
|
"constexpr __uint128_t large_int = 0xffffffffffffffff;"
|
|
|
|
"constexpr __uint128_t small_int = 1;"
|
2013-06-04 03:37:18 +08:00
|
|
|
"\n#endif\n"
|
2013-06-03 21:51:33 +08:00
|
|
|
"constexpr double d1 = 42.42;"
|
|
|
|
"constexpr long double d2 = 42.42;"
|
|
|
|
"constexpr _Complex long double c1 = 42.0i;"
|
|
|
|
"constexpr _Complex long double c2 = 42.0;"
|
|
|
|
"template<int N> struct A : A<N-1> {};"
|
|
|
|
"template<> struct A<0> { int n; }; A<50> a;"
|
|
|
|
"constexpr int &r = a.n;"
|
|
|
|
"constexpr int A<50>::*p = &A<50>::n;"
|
|
|
|
"void f() { foo: bar: constexpr int k = __builtin_constant_p(0) ?"
|
|
|
|
" (char*)&&foo - (char*)&&bar : 0; }",
|
|
|
|
Args));
|
|
|
|
|
|
|
|
// FIXME: Once this test starts breaking we can test APValue::needsCleanup
|
|
|
|
// for ComplexInt.
|
|
|
|
ASSERT_FALSE(runToolOnCodeWithArgs(
|
|
|
|
Factory->create(),
|
|
|
|
"constexpr _Complex __uint128_t c = 0xffffffffffffffff;",
|
|
|
|
Args));
|
|
|
|
}
|