48 changes: 35 additions & 13 deletions clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "clang-include-cleaner/Types.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileEntry.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Frontend/CompilerInvocation.h"
Expand All @@ -24,6 +25,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Testing/Annotations/Annotations.h"
Expand Down Expand Up @@ -53,9 +55,11 @@ MATCHER_P(named, N, "") {
}

MATCHER_P(FileNamed, N, "") {
if (arg.getFileEntry().tryGetRealPathName() == N)
llvm::StringRef ActualName =
llvm::sys::path::remove_leading_dotslash(arg.getName());
if (ActualName == N)
return true;
*result_listener << arg.getFileEntry().tryGetRealPathName().str();
*result_listener << ActualName.str();
return false;
}

Expand Down Expand Up @@ -317,7 +321,8 @@ class PragmaIncludeTest : public ::testing::Test {
}

TestAST build(bool ResetPragmaIncludes = true) {
if (ResetPragmaIncludes) PI = PragmaIncludes();
if (ResetPragmaIncludes)
PI = PragmaIncludes();
return TestAST(Inputs);
}

Expand Down Expand Up @@ -535,16 +540,33 @@ TEST_F(PragmaIncludeTest, IWYUExportBlock) {
TestAST Processed = build();
auto &FM = Processed.fileManager();

EXPECT_THAT(PI.getExporters(FM.getFile("private1.h").get(), FM),
testing::UnorderedElementsAre(FileNamed("export1.h"),
FileNamed("normal.h")));
EXPECT_THAT(PI.getExporters(FM.getFile("private2.h").get(), FM),
testing::UnorderedElementsAre(FileNamed("export1.h")));
EXPECT_THAT(PI.getExporters(FM.getFile("private3.h").get(), FM),
testing::UnorderedElementsAre(FileNamed("export1.h")));

EXPECT_TRUE(PI.getExporters(FM.getFile("foo.h").get(), FM).empty());
EXPECT_TRUE(PI.getExporters(FM.getFile("bar.h").get(), FM).empty());
auto GetNames = [](llvm::ArrayRef<FileEntryRef> FEs) {
std::string Result;
llvm::raw_string_ostream OS(Result);
for (auto &FE : FEs) {
OS << FE.getName() << " ";
}
OS.flush();
return Result;
};
auto Exporters = PI.getExporters(FM.getFile("private1.h").get(), FM);
EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h"),
FileNamed("normal.h")))
<< GetNames(Exporters);

Exporters = PI.getExporters(FM.getFile("private2.h").get(), FM);
EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h")))
<< GetNames(Exporters);

Exporters = PI.getExporters(FM.getFile("private3.h").get(), FM);
EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h")))
<< GetNames(Exporters);

Exporters = PI.getExporters(FM.getFile("foo.h").get(), FM);
EXPECT_TRUE(Exporters.empty()) << GetNames(Exporters);

Exporters = PI.getExporters(FM.getFile("bar.h").get(), FM);
EXPECT_TRUE(Exporters.empty()) << GetNames(Exporters);
}

TEST_F(PragmaIncludeTest, SelfContained) {
Expand Down
18 changes: 9 additions & 9 deletions clang-tools-extra/test/clang-doc/basic-project.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// See https://github.com/llvm/llvm-project/issues/97507.
// UNSUPPORTED: target={{.*}}

// RUN: rm -rf %t && mkdir -p %t/docs %t/build
// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json
// RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
Expand Down Expand Up @@ -61,13 +58,13 @@
// HTML-SHAPE: <p>Defined at line 8 of file {{.*}}Shape.h</p>
// HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
// HTML-SHAPE: <h2 id="Functions">Functions</h2>
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
// HTML-SHAPE: <p>public void ~Shape()</p>
// HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
// HTML-SHAPE: <p>public double area()</p>
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
// HTML-SHAPE: <p>public double perimeter()</p>
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
// HTML-SHAPE: <p>public void ~Shape()</p>
// HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>

// HTML-CALC: <h1>class Calculator</h1>
// HTML-CALC: <p>Defined at line 8 of file {{.*}}Calculator.h</p>
Expand All @@ -94,8 +91,10 @@
// HTML-RECTANGLE: <a href="Shape.html">Shape</a>
// HTML-RECTANGLE: </p>
// HTML-RECTANGLE: <h2 id="Members">Members</h2>
// HTML-RECTANGLE: <li>private double width_</li>
// HTML-RECTANGLE: <li>private double height_</li>
// HTML-RECTANGLE: <p> Width of the rectangle.</p>
// HTML-RECTANGLE: <div>private double width_</div>
// HTML-RECTANGLE: <p> Height of the rectangle.</p>
// HTML-RECTANGLE: <div>private double height_</div>
// HTML-RECTANGLE: <h2 id="Functions">Functions</h2>
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
Expand All @@ -115,7 +114,8 @@
// HTML-CIRCLE: <a href="Shape.html">Shape</a>
// HTML-CIRCLE: </p>
// HTML-CIRCLE: <h2 id="Members">Members</h2>
// HTML-CIRCLE: <li>private double radius_</li>
// HTML-CIRCLE: <p> Radius of the circle.</p>
// HTML-CIRCLE: <div>private double radius_</div>
// HTML-CIRCLE: <h2 id="Functions">Functions</h2>
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
// HTML-CIRCLE: <p>public void Circle(double radius)</p>
Expand Down
6 changes: 4 additions & 2 deletions clang-tools-extra/test/clang-doc/namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,16 @@ namespace AnotherNamespace {
// HTML-GLOBAL-INDEX: <h1>Global Namespace</h1>
// HTML-GLOBAL-INDEX: <h2 id="Namespaces">Namespaces</h2>
// HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
// HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>
// HTML-GLOBAL-INDEX: <li>AnotherNamespace</li>
// HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>


// MD-GLOBAL-INDEX: # Global Namespace
// MD-GLOBAL-INDEX: ## Namespaces
// MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
// MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)
// MD-GLOBAL-INDEX: * [AnotherNamespace](..{{[\/]}}AnotherNamespace{{[\/]}}index.md)
// MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)


// MD-ALL-FILES: # All Files
// MD-ALL-FILES: ## [@nonymous_namespace](@nonymous_namespace{{[\/]}}index.md)
Expand Down
34 changes: 17 additions & 17 deletions clang-tools-extra/test/clang-doc/templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ void ParamPackFunction(T... args);
// CHECK: ---
// CHECK-NEXT: USR: '{{([0-9A-F]{40})}}'
// CHECK-NEXT: ChildFunctions:
// CHECK-NEXT: - USR: '{{([0-9A-F]{40})}}'
// CHECK-NEXT: Name: 'ParamPackFunction'
// CHECK-NEXT: Location:
// CHECK-NEXT: - LineNumber: 16
// CHECK-NEXT: Filename: '{{.*}}'
// CHECK-NEXT: Params:
// CHECK-NEXT: - Type:
// CHECK-NEXT: Name: 'T...'
// CHECK-NEXT: QualName: 'T...'
// CHECK-NEXT: Name: 'args'
// CHECK-NEXT: ReturnType:
// CHECK-NEXT: Type:
// CHECK-NEXT: Name: 'void'
// CHECK-NEXT: QualName: 'void'
// CHECK-NEXT: Template:
// CHECK-NEXT: Params:
// CHECK-NEXT: - Contents: 'class... T'
// CHECK-NEXT: - USR: '{{([0-9A-F]{40})}}'
// CHECK-NEXT: Name: 'function'
// CHECK-NEXT: DefLocation:
Expand Down Expand Up @@ -56,21 +73,4 @@ void ParamPackFunction(T... args);
// CHECK-NEXT: Params:
// CHECK-NEXT: - Contents: 'bool'
// CHECK-NEXT: - Contents: '0'
// CHECK-NEXT: - USR: '{{([0-9A-F]{40})}}'
// CHECK-NEXT: Name: 'ParamPackFunction'
// CHECK-NEXT: Location:
// CHECK-NEXT: - LineNumber: 16
// CHECK-NEXT: Filename: '{{.*}}'
// CHECK-NEXT: Params:
// CHECK-NEXT: - Type:
// CHECK-NEXT: Name: 'T...'
// CHECK-NEXT: QualName: 'T...'
// CHECK-NEXT: Name: 'args'
// CHECK-NEXT: ReturnType:
// CHECK-NEXT: Type:
// CHECK-NEXT: Name: 'void'
// CHECK-NEXT: QualName: 'void'
// CHECK-NEXT: Template:
// CHECK-NEXT: Params:
// CHECK-NEXT: - Contents: 'class... T'
// CHECK-NEXT: ...
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ T qux(T Generic) {
async::Future<T> TemplateType;
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: unused local variable 'TemplateType' of type 'async::Future<T>' [bugprone-unused-local-non-trivial-variable]
a::Future<T> AliasTemplateType;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: unused local variable 'AliasTemplateType' of type 'a::Future<T>' (aka 'Future<type-parameter-0-0>') [bugprone-unused-local-non-trivial-variable]
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: unused local variable 'AliasTemplateType' of type 'a::Future<T>' (aka 'Future<T>') [bugprone-unused-local-non-trivial-variable]
[[maybe_unused]] async::Future<Units> MaybeUnused;
return Generic;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

namespace absl
{
// Use const char * for the format since the real type is hard to mock up.
template <typename... Args>
std::string StrFormat(const char *format, const Args&... args);
template <typename S, typename... Args>
std::string StrFormat(const S &format, const Args&... args);
} // namespace absl

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ struct shared_ptr {
explicit operator bool() const noexcept;
};

template <typename T>
struct vector {
vector();
bool operator==(const vector<T>& other) const;
bool operator!=(const vector<T>& other) const;
unsigned long size() const;
bool empty() const;

using iterator = T*;

iterator begin();
iterator end();

T* data;
unsigned long sz;
};

} // namespace std

struct Bar {
Expand Down Expand Up @@ -235,3 +252,34 @@ void Negative() {
if (MACRO(x) == nullptr)
;
}

void test_redundant_get() {
std::vector<std::shared_ptr<int>> v;
auto f = [](int) {};
for (auto i = v.begin(); i != v.end(); ++i) {
f(*i->get());
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
// CHECK-FIXES: f(**i);
}
}

struct Inner {
int a;
int *getValue() { return &a; }
};

struct Example {
Inner inner;
Inner* get() { return &inner; }
int *getValue() { return inner.getValue(); }
};

void test_redundant_get_with_member() {
std::vector<std::shared_ptr<Example>> v;
auto f = [](int) {};
for (auto i = v.begin(); i != v.end(); ++i) {
f(*(*i).get()->get()->getValue());
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
// CHECK-FIXES: f(**i->get()->getValue());
}
}
4 changes: 3 additions & 1 deletion clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ TEST(HTMLGeneratorTest, emitRecordHTML) {
</p>
<h2 id="Members">Members</h2>
<ul>
<li>private int X</li>
<li>
<div>private int X</div>
</li>
</ul>
<h2 id="Records">Records</h2>
<ul>
Expand Down
243 changes: 115 additions & 128 deletions clang/bindings/python/clang/cindex.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def find_function_declarations(node, declarations=[]):
if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
declarations.append((node.spelling, node.exception_specification_kind))
declarations.append(node)
for child in node.get_children():
declarations = find_function_declarations(child, declarations)
return declarations
Expand All @@ -33,4 +33,12 @@ def test_exception_specification_kind(self):
("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT),
("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT),
]
self.assertListEqual(declarations, expected)
from_cursor = [
(node.spelling, node.exception_specification_kind) for node in declarations
]
from_type = [
(node.spelling, node.type.get_exception_specification_kind())
for node in declarations
]
self.assertListEqual(from_cursor, expected)
self.assertListEqual(from_type, expected)
8 changes: 3 additions & 5 deletions clang/cmake/caches/Fuchsia-stage2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ if(FUCHSIA_SDK)
set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS "aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
endif()

foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
foreach(target armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi)
list(APPEND BUILTIN_TARGETS "${target}")
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
foreach(lang C;CXX;ASM)
set(BUILTINS_${target}_CMAKE_${lang}_local_flags "--target=${target} -mthumb")
if(${target} STREQUAL "armv8m.main-unknown-eabi")
if(${target} STREQUAL "armv8m.main-none-eabi")
set(BUILTINS_${target}_CMAKE_${lang}_local_flags "${BUILTINS_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
endif()
set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "${BUILTINS_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")
Expand All @@ -328,7 +328,7 @@ foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
# TODO: The preprocessor defines workaround various issues in libc and libc++ integration.
# These should be addressed and removed over time.
set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "--target=${target} -mthumb -Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" \"-Dtimeval=struct timeval{int tv_sec; int tv_usec;}\" \"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1")
if(${target} STREQUAL "armv8m.main-unknown-eabi")
if(${target} STREQUAL "armv8m.main-none-eabi")
set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "${RUNTIMES_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
endif()
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "${RUNTIMES_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")
Expand All @@ -343,7 +343,6 @@ foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
Expand Down Expand Up @@ -395,7 +394,6 @@ foreach(target riscv32-unknown-elf)
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
Expand Down
Loading