Skip to content

Commit c176ed1

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:caf0897c9c7f6f2a142af06bff8680a23d1d4bf5 into amd-gfx:bd53c0b2e9b9
Local branch amd-gfx bd53c0b Merged main:21627236363d629f6a5b820f45a6071371e4b8db into amd-gfx:842efb6db236 Remote branch main caf0897 [SPIR-V] Fix deprecation warnings after llvm#102608 (llvm#109447)
2 parents bd53c0b + caf0897 commit c176ed1

File tree

53 files changed

+1104
-778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1104
-778
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
============================
2+
External Clang-Tidy Examples
3+
============================
4+
5+
Introduction
6+
============
7+
8+
This page provides examples of what people have done with :program:`clang-tidy` that
9+
might serve as useful guides (or starting points) to develop your own checks.
10+
They may be helpful for necessary things such as how to write the `CMakeLists.txt`
11+
for an out-of-tree plugin of :program:`clang-tidy` checks.
12+
13+
If you know of (or wrote!) a tool or project using :program:`clang-tidy`, please share it
14+
on `the Discourse forums (Clang Frontend category)
15+
<https://discourse.llvm.org/c/clang/6>`_ for wider visibility and open a
16+
pull-request on `LLVM Github`_ to have it added here. Since the primary purpose of
17+
this page is to provide examples that can help developers, the listed projects should
18+
have code available.
19+
20+
As :program:`clang-tidy` is using, for example, the AST Matchers and diagnostics of Clang,
21+
`External Clang Examples`_ may also be useful to look at for such examples.
22+
23+
.. _LLVM Github: https://github.com/llvm/llvm-project
24+
.. _External Clang Examples: https://clang.llvm.org/docs/ExternalClangExamples.html
25+
26+
List of projects and tools
27+
==========================
28+
29+
`<https://github.com/coveooss/clang-tidy-plugin-examples>`_
30+
"This folder contains :program:`clang-tidy` plugins."

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See also:
1212
The list of clang-tidy checks <checks/list>
1313
Clang-tidy IDE/Editor Integrations <Integrations>
1414
Getting Involved <Contributing>
15+
External Clang-Tidy Examples <ExternalClang-TidyExamples>
1516

1617
:program:`clang-tidy` is a clang-based C++ "linter" tool. Its purpose is to
1718
provide an extensible framework for diagnosing and fixing typical programming

clang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
917917
-data ${BOLT_FDATA}
918918
-reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions
919919
-split-all-cold -split-eh -dyno-stats -use-gnu-stack
920-
-split-strategy=cdsplit -update-debug-sections
920+
-update-debug-sections
921921
${BOLT_NO_LBR}
922922
COMMENT "Optimizing Clang with BOLT"
923923
USES_TERMINAL

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13649,7 +13649,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
1364913649
else
1365013650
InitValStr = std::to_string(InitVal.getZExtValue());
1365113651
std::string EnumStr = Enumerator->getNameAsString() + ":" + InitValStr;
13652-
Value *EnumStrVal = Builder.CreateGlobalStringPtr(EnumStr);
13652+
Value *EnumStrVal = Builder.CreateGlobalString(EnumStr);
1365313653

1365413654
ConstantInt *Flag = cast<ConstantInt>(EmitScalarExpr(E->getArg(1)));
1365513655
Value *FlagValue = ConstantInt::get(Int64Ty, Flag->getSExtValue());

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ ScalarExprEmitter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
18071807
ASTContext &Context = CGF.getContext();
18081808
unsigned AddrSpace =
18091809
Context.getTargetAddressSpace(CGF.CGM.GetGlobalConstantAddressSpace());
1810-
llvm::Constant *GlobalConstStr = Builder.CreateGlobalStringPtr(
1810+
llvm::Constant *GlobalConstStr = Builder.CreateGlobalString(
18111811
E->ComputeName(Context), "__usn_str", AddrSpace);
18121812

18131813
llvm::Type *ExprTy = ConvertType(E->getType());

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
815815
// C99 6.8.4.1: The first substatement is executed if the expression compares
816816
// unequal to 0. The condition must be a scalar type.
817817
LexicalScope ConditionScope(*this, S.getCond()->getSourceRange());
818+
ApplyDebugLocation DL(*this, S.getCond());
818819

819820
if (S.getInit())
820821
EmitStmt(S.getInit());

clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ static std::optional<std::string> printReferrer(const MemRegion *Referrer) {
337337
// warn_bind_ref_member_to_parameter or
338338
// warn_init_ptr_member_to_parameter_addr
339339
return std::nullopt;
340+
} else if (isa<AllocaRegion>(Referrer)) {
341+
// Skip alloca() regions, they indicate advanced memory management
342+
// and higher likelihood of CSA false positives.
343+
return std::nullopt;
340344
} else {
341345
assert(false && "Unexpected referrer region type.");
342346
return std::nullopt;

clang/test/Analysis/stack-addr-ps.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s -Wno-undefined-bool-conversion
1+
// RUN: %clang_analyze_cc1 \
2+
// RUN: -analyzer-checker=core,debug.ExprInspection \
3+
// RUN: -verify %s \
4+
// RUN: -Wno-undefined-bool-conversion
5+
// RUN: %clang_analyze_cc1 \
6+
// RUN: -analyzer-checker=core,debug.ExprInspection,unix.Malloc \
7+
// RUN: -verify %s \
8+
// RUN: -Wno-undefined-bool-conversion
9+
// unix.Malloc is necessary to model __builtin_alloca,
10+
// which could trigger an "unexpected region" bug in StackAddrEscapeChecker.
211

312
typedef __INTPTR_TYPE__ intptr_t;
413

514
template <typename T>
615
void clang_analyzer_dump(T x);
716

17+
using size_t = decltype(sizeof(int));
18+
void * malloc(size_t size);
19+
void free(void*);
20+
821
const int& g() {
922
int s;
1023
return s; // expected-warning{{Address of stack memory associated with local variable 's' returned}} expected-warning{{reference to stack memory associated with local variable 's' returned}}
@@ -846,3 +859,21 @@ void top(char **p) {
846859
foo(); // no-warning FIXME: p binding is reclaimed before the function end
847860
}
848861
} // namespace early_reclaim_dead_limitation
862+
863+
namespace alloca_region_pointer {
864+
void callee(char **pptr) {
865+
char local;
866+
*pptr = &local;
867+
} // no crash
868+
869+
void top_alloca_no_crash_fn() {
870+
char **pptr = (char**)__builtin_alloca(sizeof(char*));
871+
callee(pptr);
872+
}
873+
874+
void top_malloc_no_crash_fn() {
875+
char **pptr = (char**)malloc(sizeof(char*));
876+
callee(pptr);
877+
free(pptr);
878+
}
879+
} // namespace alloca_region_pointer
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -debug-info-kind=limited -gno-column-info -triple=x86_64-pc-linux -emit-llvm %s -o - | FileCheck %s
2+
3+
// The important thing is that the compare and the conditional branch have
4+
// locs with the same scope (the lexical block for the 'if'). By turning off
5+
// column info, they end up with the same !dbg record, which halves the number
6+
// of checks to verify the scope.
7+
8+
int c = 2;
9+
10+
int f() {
11+
#line 100
12+
if (int a = 5; a > c)
13+
return 1;
14+
return 0;
15+
}
16+
// CHECK-LABEL: define {{.*}} @_Z1fv()
17+
// CHECK: = icmp {{.*}} !dbg [[F_CMP:![0-9]+]]
18+
// CHECK-NEXT: br i1 {{.*}} !dbg [[F_CMP]]
19+
20+
int g() {
21+
#line 200
22+
if (int a = f())
23+
return 2;
24+
return 3;
25+
}
26+
// CHECK-LABEL: define {{.*}} @_Z1gv()
27+
// CHECK: = icmp {{.*}} !dbg [[G_CMP:![0-9]+]]
28+
// CHECK-NEXT: br i1 {{.*}} !dbg [[G_CMP]]
29+
30+
int h() {
31+
#line 300
32+
if (c > 3)
33+
return 4;
34+
return 5;
35+
}
36+
// CHECK-LABEL: define {{.*}} @_Z1hv()
37+
// CHECK: = icmp {{.*}} !dbg [[H_CMP:![0-9]+]]
38+
// CHECK-NEXT: br i1 {{.*}} !dbg [[H_CMP]]
39+
40+
// CHECK-DAG: [[F_CMP]] = !DILocation(line: 100, scope: [[F_SCOPE:![0-9]+]]
41+
// CHECK-DAG: [[F_SCOPE]] = distinct !DILexicalBlock({{.*}} line: 100)
42+
// CHECK-DAG: [[G_CMP]] = !DILocation(line: 200, scope: [[G_SCOPE:![0-9]+]]
43+
// CHECK-DAG: [[G_SCOPE]] = distinct !DILexicalBlock({{.*}} line: 200)
44+
// CHECK-DAG: [[H_CMP]] = !DILocation(line: 300, scope: [[H_SCOPE:![0-9]+]]
45+
// CHECK-DAG: [[H_SCOPE]] = distinct !DILexicalBlock({{.*}} line: 300)

compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
RUN: rm -rf %t && split-file %s %t && cd %t
2-
RUN: %clang_pgogen -fPIC foo.c -c -Xclang -fprofile-instrument-path="default_foo_%m.profraw"
3-
RUN: %clang_pgogen -fPIC foo2.c -c -Xclang -fprofile-instrument-path="default_foo2_%m.profraw"
4-
RUN: %clang_pgogen -shared foo.o -o shr_foo.o %if target={{.*aix.*}} %{ -bcdtors:mbr %}
5-
RUN: %clang_pgogen -shared foo2.o -o shr_foo2.o
2+
RUN: %clang_pgogen -fprofile-update=atomic -fPIC foo.c -c -Xclang -fprofile-instrument-path="default_foo_%m.profraw"
3+
RUN: %clang_pgogen -fprofile-update=atomic -fPIC foo2.c -c -Xclang -fprofile-instrument-path="default_foo2_%m.profraw"
4+
RUN: %clang_pgogen -fprofile-update=atomic -shared foo.o -o shr_foo.o %if target={{.*aix.*}} %{ -bcdtors:mbr %}
5+
RUN: %clang_pgogen -fprofile-update=atomic -shared foo2.o -o shr_foo2.o
66

77
RUN: %clang_pgogen common.c -c
88

0 commit comments

Comments
 (0)