Skip to content

Commit f899220

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:8c0090030bf8 into amd-gfx:4088678579a3
Local branch amd-gfx 4088678 Merged main:53d080c5b5df into amd-gfx:f0fbc982ed3b Remote branch main 8c00900 [llvm]Add a simple Telemetry framework (llvm#102323)
2 parents 4088678 + 8c00900 commit f899220

File tree

405 files changed

+6183
-3693
lines changed

Some content is hidden

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

405 files changed

+6183
-3693
lines changed

bolt/lib/Core/Relocation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static bool isSupportedAArch64(uint64_t Type) {
7575
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7676
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
7777
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
78+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
79+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
7880
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
7981
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
8082
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
@@ -183,6 +185,8 @@ static size_t getSizeForTypeAArch64(uint64_t Type) {
183185
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
184186
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
185187
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
188+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
189+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
186190
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
187191
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
188192
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
@@ -651,6 +655,8 @@ static bool isTLSAArch64(uint64_t Type) {
651655
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
652656
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
653657
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
658+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
659+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
654660
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
655661
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
656662
case ELF::R_AARCH64_TLSDESC_CALL:
@@ -716,6 +722,8 @@ static bool isPCRelativeAArch64(uint64_t Type) {
716722
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
717723
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
718724
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
725+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
726+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
719727
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
720728
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
721729
case ELF::R_AARCH64_TLSDESC_ADD_LO12:

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
14491449
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
14501450
case ELF::R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
14511451
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
1452+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
1453+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
14521454
case ELF::R_AARCH64_MOVW_UABS_G0:
14531455
case ELF::R_AARCH64_MOVW_UABS_G0_NC:
14541456
case ELF::R_AARCH64_MOVW_UABS_G1:

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,40 @@ This check will flag:
2727
- All applications of binary operators with a narrowing conversions.
2828
For example: ``int i; i+= 0.1;``.
2929

30+
Arithmetic with smaller integer types than ``int`` trigger implicit conversions,
31+
as explained under `"Integral Promotion" on cppreference.com
32+
<https://en.cppreference.com/w/cpp/language/implicit_conversion>`_.
33+
This check diagnoses more instances of narrowing than the compiler warning
34+
`-Wconversion` does. The example below demonstrates this behavior.
35+
36+
.. code-block:: c++
37+
38+
// The following function definition demonstrates usage of arithmetic with
39+
// integer types smaller than `int` and how the narrowing conversion happens
40+
// implicitly.
41+
void computation(short argument1, short argument2) {
42+
// Arithmetic written by humans:
43+
short result = argument1 + argument2;
44+
// Arithmetic actually performed by C++:
45+
short result = static_cast<short>(static_cast<int>(argument1) + static_cast<int>(argument2));
46+
}
47+
48+
void recommended_resolution(short argument1, short argument2) {
49+
short result = argument1 + argument2;
50+
// ^ warning: narrowing conversion from 'int' to signed type 'short' is implementation-defined
51+
52+
// The cppcoreguidelines recommend to resolve this issue by using the GSL
53+
// in one of two ways. Either by a cast that throws if a loss of precision
54+
// would occur.
55+
short result = gsl::narrow<short>(argument1 + argument2);
56+
// Or it can be resolved without checking the result risking invalid results.
57+
short result = gsl::narrow_cast<short>(argument1 + argument2);
58+
59+
// A classical `static_cast` will silence the warning as well if the GSL
60+
// is not available.
61+
short result = static_cast<short>(argument1 + argument2);
62+
}
63+
3064

3165
Options
3266
-------
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//===-- SmartPointerAccessorCaching.h ---------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines utilities to help cache accessors for smart pointer
10+
// like objects.
11+
//
12+
// These should be combined with CachedConstAccessorsLattice.
13+
// Beyond basic const accessors, smart pointers may have the following two
14+
// additional issues:
15+
//
16+
// 1) There may be multiple accessors for the same underlying object, e.g.
17+
// `operator->`, `operator*`, and `get`. Users may use a mixture of these
18+
// accessors, so the cache should unify them.
19+
//
20+
// 2) There may be non-const overloads of accessors. They are still safe to
21+
// cache, as they don't modify the container object.
22+
//===----------------------------------------------------------------------===//
23+
24+
#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
25+
#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
26+
27+
#include <cassert>
28+
29+
#include "clang/AST/Decl.h"
30+
#include "clang/AST/Stmt.h"
31+
#include "clang/ASTMatchers/ASTMatchers.h"
32+
33+
namespace clang::dataflow {
34+
35+
/// Matchers:
36+
/// For now, these match on any class with an `operator*` or `operator->`
37+
/// where the return types have a similar shape as std::unique_ptr
38+
/// and std::optional.
39+
///
40+
/// - `*` returns a reference to a type `T`
41+
/// - `->` returns a pointer to `T`
42+
/// - `get` returns a pointer to `T`
43+
/// - `value` returns a reference `T`
44+
///
45+
/// (1) The `T` should all match across the accessors (ignoring qualifiers).
46+
///
47+
/// (2) The specific accessor used in a call isn't required to be const,
48+
/// but the class must have a const overload of each accessor.
49+
///
50+
/// For now, we don't have customization to ignore certain classes.
51+
/// For example, if writing a ClangTidy check for `std::optional`, these
52+
/// would also match `std::optional`. In order to have special handling
53+
/// for `std::optional`, we assume the (Matcher, TransferFunction) case
54+
/// with custom handling is ordered early so that these generic cases
55+
/// do not trigger.
56+
ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar();
57+
ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow();
58+
ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall();
59+
ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall();
60+
61+
} // namespace clang::dataflow
62+
63+
#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@ def warn_typecheck_vector_element_sizes_not_equal : Warning<
34233423
def err_ext_vector_component_exceeds_length : Error<
34243424
"vector component access exceeds type %0">;
34253425
def err_ext_vector_component_name_illegal : Error<
3426-
"illegal vector component name '%0'">;
3426+
"illegal vector component name %0">;
34273427
def err_attribute_address_space_negative : Error<
34283428
"address space is negative">;
34293429
def err_attribute_address_space_too_high : Error<

clang/lib/Analysis/FlowSensitive/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_clang_library(clangAnalysisFlowSensitive
1010
Logger.cpp
1111
RecordOps.cpp
1212
SimplifyConstraints.cpp
13+
SmartPointerAccessorCaching.cpp
1314
Transfer.cpp
1415
TypeErasedDataflowAnalysis.cpp
1516
Value.cpp
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#include "clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h"
2+
3+
#include "clang/AST/CanonicalType.h"
4+
#include "clang/AST/DeclCXX.h"
5+
#include "clang/ASTMatchers/ASTMatchers.h"
6+
#include "clang/ASTMatchers/ASTMatchersMacros.h"
7+
#include "clang/Basic/OperatorKinds.h"
8+
9+
namespace clang::dataflow {
10+
11+
namespace {
12+
13+
using ast_matchers::callee;
14+
using ast_matchers::cxxMemberCallExpr;
15+
using ast_matchers::cxxMethodDecl;
16+
using ast_matchers::cxxOperatorCallExpr;
17+
using ast_matchers::hasName;
18+
using ast_matchers::hasOverloadedOperatorName;
19+
using ast_matchers::ofClass;
20+
using ast_matchers::parameterCountIs;
21+
using ast_matchers::pointerType;
22+
using ast_matchers::referenceType;
23+
using ast_matchers::returns;
24+
25+
bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
26+
bool &HasValue) {
27+
// We may want to cache this search, but in current profiles it hasn't shown
28+
// up as a hot spot (possibly because there aren't many hits, relatively).
29+
bool HasArrow = false;
30+
bool HasStar = false;
31+
CanQualType StarReturnType, ArrowReturnType, GetReturnType, ValueReturnType;
32+
for (const auto *MD : RD.methods()) {
33+
// We only consider methods that are const and have zero parameters.
34+
// It may be that there is a non-const overload for the method, but
35+
// there should at least be a const overload as well.
36+
if (!MD->isConst() || MD->getNumParams() != 0)
37+
continue;
38+
switch (MD->getOverloadedOperator()) {
39+
case OO_Star:
40+
if (MD->getReturnType()->isReferenceType()) {
41+
HasStar = true;
42+
StarReturnType = MD->getReturnType()
43+
.getNonReferenceType()
44+
->getCanonicalTypeUnqualified();
45+
}
46+
break;
47+
case OO_Arrow:
48+
if (MD->getReturnType()->isPointerType()) {
49+
HasArrow = true;
50+
ArrowReturnType = MD->getReturnType()
51+
->getPointeeType()
52+
->getCanonicalTypeUnqualified();
53+
}
54+
break;
55+
case OO_None: {
56+
IdentifierInfo *II = MD->getIdentifier();
57+
if (II == nullptr)
58+
continue;
59+
if (II->isStr("get")) {
60+
if (MD->getReturnType()->isPointerType()) {
61+
HasGet = true;
62+
GetReturnType = MD->getReturnType()
63+
->getPointeeType()
64+
->getCanonicalTypeUnqualified();
65+
}
66+
} else if (II->isStr("value")) {
67+
if (MD->getReturnType()->isReferenceType()) {
68+
HasValue = true;
69+
ValueReturnType = MD->getReturnType()
70+
.getNonReferenceType()
71+
->getCanonicalTypeUnqualified();
72+
}
73+
}
74+
} break;
75+
default:
76+
break;
77+
}
78+
}
79+
80+
if (!HasStar || !HasArrow || StarReturnType != ArrowReturnType)
81+
return false;
82+
HasGet = HasGet && (GetReturnType == StarReturnType);
83+
HasValue = HasValue && (ValueReturnType == StarReturnType);
84+
return true;
85+
}
86+
87+
} // namespace
88+
} // namespace clang::dataflow
89+
90+
// AST_MATCHER macros create an "internal" namespace, so we put it in
91+
// its own anonymous namespace instead of in clang::dataflow.
92+
namespace {
93+
94+
AST_MATCHER(clang::CXXRecordDecl, smartPointerClassWithGet) {
95+
bool HasGet = false;
96+
bool HasValue = false;
97+
bool HasStarAndArrow =
98+
clang::dataflow::hasSmartPointerClassShape(Node, HasGet, HasValue);
99+
return HasStarAndArrow && HasGet;
100+
}
101+
102+
AST_MATCHER(clang::CXXRecordDecl, smartPointerClassWithValue) {
103+
bool HasGet = false;
104+
bool HasValue = false;
105+
bool HasStarAndArrow =
106+
clang::dataflow::hasSmartPointerClassShape(Node, HasGet, HasValue);
107+
return HasStarAndArrow && HasValue;
108+
}
109+
110+
AST_MATCHER(clang::CXXRecordDecl, smartPointerClassWithGetOrValue) {
111+
bool HasGet = false;
112+
bool HasValue = false;
113+
bool HasStarAndArrow =
114+
clang::dataflow::hasSmartPointerClassShape(Node, HasGet, HasValue);
115+
return HasStarAndArrow && (HasGet || HasValue);
116+
}
117+
118+
} // namespace
119+
120+
namespace clang::dataflow {
121+
122+
ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar() {
123+
return cxxOperatorCallExpr(
124+
hasOverloadedOperatorName("*"),
125+
callee(cxxMethodDecl(parameterCountIs(0), returns(referenceType()),
126+
ofClass(smartPointerClassWithGetOrValue()))));
127+
}
128+
129+
ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow() {
130+
return cxxOperatorCallExpr(
131+
hasOverloadedOperatorName("->"),
132+
callee(cxxMethodDecl(parameterCountIs(0), returns(pointerType()),
133+
ofClass(smartPointerClassWithGetOrValue()))));
134+
}
135+
ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall() {
136+
return cxxMemberCallExpr(callee(
137+
cxxMethodDecl(parameterCountIs(0), returns(referenceType()),
138+
hasName("value"), ofClass(smartPointerClassWithValue()))));
139+
}
140+
141+
ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall() {
142+
return cxxMemberCallExpr(callee(
143+
cxxMethodDecl(parameterCountIs(0), returns(pointerType()), hasName("get"),
144+
ofClass(smartPointerClassWithGet()))));
145+
}
146+
147+
} // namespace clang::dataflow

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,11 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
434434
if (!HalvingSwizzle && *compStr) {
435435
// We didn't get to the end of the string. This means the component names
436436
// didn't come from the same set *or* we encountered an illegal name.
437-
S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal)
438-
<< StringRef(compStr, 1) << SourceRange(CompLoc);
437+
size_t Offset = compStr - CompName->getNameStart() + 1;
438+
char Fmt[3] = {'\'', *compStr, '\''};
439+
S.Diag(OpLoc.getLocWithOffset(Offset),
440+
diag::err_ext_vector_component_name_illegal)
441+
<< StringRef(Fmt, 3) << SourceRange(CompLoc);
439442
return QualType();
440443
}
441444

clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class TextDiagnostics : public PathDiagnosticConsumer {
8181

8282
if (llvm::Error Err = Repls.add(Repl)) {
8383
llvm::errs() << "Error applying replacement " << Repl.toString()
84-
<< ": " << Err << "\n";
84+
<< ": " << llvm::toString(std::move(Err)) << "\n";
8585
}
8686
}
8787
};

clang/test/SemaCXX/vector-bool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ void foo(const bool& X);
8585

8686
// Disallow element-wise access.
8787
bool* ElementRefs() {
88-
eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}}
89-
&eight_bools.z; // expected-error@89 {{illegal vector component name ''z''}}
90-
foo(eight_bools.w); // expected-error@90 {{illegal vector component name ''w''}}
91-
foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}}
88+
eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}}
89+
&eight_bools.z; // expected-error@89 {{illegal vector component name 'z'}}
90+
foo(eight_bools.w); // expected-error@90 {{illegal vector component name 'w'}}
91+
foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}}
9292
}
9393

9494
void Sizeof() {

clang/unittests/Analysis/FlowSensitive/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_clang_unittest(ClangAnalysisFlowSensitiveTests
2121
SignAnalysisTest.cpp
2222
SimplifyConstraintsTest.cpp
2323
SingleVarConstantPropagationTest.cpp
24+
SmartPointerAccessorCachingTest.cpp
2425
TestingSupport.cpp
2526
TestingSupportTest.cpp
2627
TransferBranchTest.cpp

0 commit comments

Comments
 (0)