Skip to content

Commit 3cdc27b

Browse files
committed
merge main into amd-staging
Change-Id: I4385997497d801b4164232276b85ef76e8dd07dc
2 parents e553a98 + 7111d03 commit 3cdc27b

Some content is hidden

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

48 files changed

+287
-243
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
#include "InitVariablesCheck.h"
1010

11+
#include "../utils/LexerUtils.h"
1112
#include "clang/AST/ASTContext.h"
13+
#include "clang/AST/Type.h"
1214
#include "clang/ASTMatchers/ASTMatchFinder.h"
13-
#include "clang/Lex/PPCallbacks.h"
1415
#include "clang/Lex/Preprocessor.h"
1516
#include <optional>
1617

@@ -107,8 +108,9 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
107108
<< MatchedDecl;
108109
if (*InitializationString != nullptr)
109110
Diagnostic << FixItHint::CreateInsertion(
110-
MatchedDecl->getLocation().getLocWithOffset(
111-
MatchedDecl->getName().size()),
111+
utils::lexer::findNextTerminator(MatchedDecl->getLocation(),
112+
*Result.SourceManager,
113+
Result.Context->getLangOpts()),
112114
*InitializationString);
113115
if (AddMathInclude) {
114116
Diagnostic << IncludeInserter.createIncludeInsertion(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ Changes in existing checks
194194
fix false positive that floating point variable is only used in increment
195195
expression.
196196

197+
- Improved :doc:`cppcoreguidelines-init-variables
198+
<clang-tidy/checks/cppcoreguidelines/init-variables>` check by fixing the
199+
insertion location for function pointers.
200+
197201
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
198202
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
199203
avoid false positive when member initialization depends on a structured
@@ -212,9 +216,9 @@ Changes in existing checks
212216
false positive for C++23 deducing this.
213217

214218
- Improved :doc:`modernize-avoid-c-arrays
215-
<clang-tidy/checks/modernize/avoid-c-arrays>` check to suggest using ``std::span``
216-
as a replacement for parameters of incomplete C array type in C++20 and
217-
``std::array`` or ``std::vector`` before C++20.
219+
<clang-tidy/checks/modernize/avoid-c-arrays>` check to suggest using
220+
``std::span`` as a replacement for parameters of incomplete C array type in
221+
C++20 and ``std::array`` or ``std::vector`` before C++20.
218222

219223
- Improved :doc:`modernize-loop-convert
220224
<clang-tidy/checks/modernize/loop-convert>` check to fix false positive when

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,17 @@ void test_clang_diagnostic_error() {
134134
// CHECK-MESSAGES: :[[@LINE-1]]:3: error: unknown type name 'UnknownType' [clang-diagnostic-error]
135135
// CHECK-FIXES-NOT: {{^}} UnknownType b = 0;{{$}}
136136
}
137+
138+
namespace gh112089 {
139+
void foo(void*);
140+
using FPtr = void(*)(void*);
141+
void test() {
142+
void(*a1)(void*);
143+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'a1' is not initialized [cppcoreguidelines-init-variables]
144+
// CHECK-FIXES: void(*a1)(void*) = nullptr;
145+
FPtr a2;
146+
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'a2' is not initialized [cppcoreguidelines-init-variables]
147+
// CHECK-FIXES: FPtr a2 = nullptr;
148+
}
149+
} // namespace gh112089
150+

clang/docs/SafeBuffers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ A relatively fresh version of C++ is recommended. In particular, the very useful
5858
standard view class ``std::span`` requires C++20.
5959

6060
Other implementations of the C++ standard library may provide different
61-
flags to enable such hardening hardening.
61+
flags to enable such hardening.
6262

6363
If you're using custom containers and views, they will need to be hardened
6464
this way as well, but you don't necessarily need to do this ahead of time.

clang/utils/TableGen/NeonEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class Intrinsic {
578578
class NeonEmitter {
579579
const RecordKeeper &Records;
580580
DenseMap<const Record *, ClassKind> ClassMap;
581-
std::map<std::string, std::deque<Intrinsic>> IntrinsicMap;
581+
std::map<std::string, std::deque<Intrinsic>, std::less<>> IntrinsicMap;
582582
unsigned UniqueNumber;
583583

584584
void createIntrinsic(const Record *R, SmallVectorImpl<Intrinsic *> &Out);
@@ -1937,9 +1937,9 @@ void Intrinsic::indexBody() {
19371937
Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
19381938
std::optional<std::string> MangledName) {
19391939
// First, look up the name in the intrinsic map.
1940-
assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
1940+
assert_with_loc(IntrinsicMap.find(Name) != IntrinsicMap.end(),
19411941
("Intrinsic '" + Name + "' not found!").str());
1942-
auto &V = IntrinsicMap.find(Name.str())->second;
1942+
auto &V = IntrinsicMap.find(Name)->second;
19431943
std::vector<Intrinsic *> GoodVec;
19441944

19451945
// Create a string to print if we end up failing.

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,10 @@ set(files
738738
__tuple/tuple_like_no_subrange.h
739739
__tuple/tuple_size.h
740740
__tuple/tuple_types.h
741-
__type_traits/add_const.h
742-
__type_traits/add_cv.h
741+
__type_traits/add_cv_quals.h
743742
__type_traits/add_lvalue_reference.h
744743
__type_traits/add_pointer.h
745744
__type_traits/add_rvalue_reference.h
746-
__type_traits/add_volatile.h
747745
__type_traits/aligned_storage.h
748746
__type_traits/aligned_union.h
749747
__type_traits/alignment_of.h

libcxx/include/__type_traits/add_const.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

libcxx/include/__type_traits/add_cv.h renamed to libcxx/include/__type_traits/add_cv_quals.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717

1818
_LIBCPP_BEGIN_NAMESPACE_STD
1919

20+
template <class _Tp>
21+
struct _LIBCPP_TEMPLATE_VIS add_const {
22+
typedef _LIBCPP_NODEBUG const _Tp type;
23+
};
24+
25+
#if _LIBCPP_STD_VER >= 14
26+
template <class _Tp>
27+
using add_const_t = typename add_const<_Tp>::type;
28+
#endif
29+
2030
template <class _Tp>
2131
struct _LIBCPP_TEMPLATE_VIS add_cv {
2232
typedef _LIBCPP_NODEBUG const volatile _Tp type;
@@ -27,6 +37,16 @@ template <class _Tp>
2737
using add_cv_t = typename add_cv<_Tp>::type;
2838
#endif
2939

40+
template <class _Tp>
41+
struct _LIBCPP_TEMPLATE_VIS add_volatile {
42+
typedef _LIBCPP_NODEBUG volatile _Tp type;
43+
};
44+
45+
#if _LIBCPP_STD_VER >= 14
46+
template <class _Tp>
47+
using add_volatile_t = typename add_volatile<_Tp>::type;
48+
#endif
49+
3050
_LIBCPP_END_NAMESPACE_STD
3151

3252
#endif // _LIBCPP___TYPE_TRAITS_ADD_CV_H

libcxx/include/__type_traits/add_volatile.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

libcxx/include/__type_traits/is_trivially_assignable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
1413
#include <__type_traits/add_lvalue_reference.h>
1514
#include <__type_traits/add_rvalue_reference.h>
1615
#include <__type_traits/integral_constant.h>

libcxx/include/__utility/as_const.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#define _LIBCPP___UTILITY_AS_CONST_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
14-
#include <__utility/forward.h>
15-
#include <__utility/move.h>
1613

1714
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1815
# pragma GCC system_header
@@ -22,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2219

2320
#if _LIBCPP_STD_VER >= 17
2421
template <class _Tp>
25-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept {
22+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& as_const(_Tp& __t) noexcept {
2623
return __t;
2724
}
2825

libcxx/include/any

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace std {
8585
#include <__memory/allocator_destructor.h>
8686
#include <__memory/allocator_traits.h>
8787
#include <__memory/unique_ptr.h>
88-
#include <__type_traits/add_const.h>
88+
#include <__type_traits/add_cv_quals.h>
8989
#include <__type_traits/add_pointer.h>
9090
#include <__type_traits/aligned_storage.h>
9191
#include <__type_traits/conditional.h>

libcxx/include/module.modulemap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ module std_core [system] {
6363
}
6464

6565
module type_traits {
66-
module add_const { header "__type_traits/add_const.h" }
67-
module add_cv { header "__type_traits/add_cv.h" }
66+
module add_cv_quals { header "__type_traits/add_cv_quals.h" }
6867
module add_lvalue_reference { header "__type_traits/add_lvalue_reference.h" }
6968
module add_pointer { header "__type_traits/add_pointer.h" }
7069
module add_rvalue_reference { header "__type_traits/add_rvalue_reference.h" }
71-
module add_volatile { header "__type_traits/add_volatile.h" }
7270
module aligned_storage { header "__type_traits/aligned_storage.h" }
7371
module aligned_union { header "__type_traits/aligned_union.h" }
7472
module alignment_of { header "__type_traits/alignment_of.h" }

libcxx/include/type_traits

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,10 @@ namespace std
425425
*/
426426

427427
#include <__config>
428-
#include <__type_traits/add_const.h>
429-
#include <__type_traits/add_cv.h>
428+
#include <__type_traits/add_cv_quals.h>
430429
#include <__type_traits/add_lvalue_reference.h>
431430
#include <__type_traits/add_pointer.h>
432431
#include <__type_traits/add_rvalue_reference.h>
433-
#include <__type_traits/add_volatile.h>
434432
#include <__type_traits/aligned_storage.h>
435433
#include <__type_traits/aligned_union.h>
436434
#include <__type_traits/alignment_of.h>

libcxx/include/variant

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,8 @@ namespace std {
226226
#include <__memory/construct_at.h>
227227
#include <__tuple/find_index.h>
228228
#include <__tuple/sfinae_helpers.h>
229-
#include <__type_traits/add_const.h>
230-
#include <__type_traits/add_cv.h>
229+
#include <__type_traits/add_cv_quals.h>
231230
#include <__type_traits/add_pointer.h>
232-
#include <__type_traits/add_volatile.h>
233231
#include <__type_traits/common_type.h>
234232
#include <__type_traits/conditional.h>
235233
#include <__type_traits/conjunction.h>

lld/ELF/Driver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,6 +2805,8 @@ static void readSecurityNotes(Ctx &ctx) {
28052805
referenceFileName = (*it)->getName();
28062806
}
28072807
}
2808+
bool hasValidPauthAbiCoreInfo = llvm::any_of(
2809+
ctx.aarch64PauthAbiCoreInfo, [](uint8_t c) { return c != 0; });
28082810

28092811
for (ELFFileBase *f : ctx.objectFiles) {
28102812
uint32_t features = f->andFeatures;
@@ -2843,10 +2845,12 @@ static void readSecurityNotes(Ctx &ctx) {
28432845
"GNU_PROPERTY_X86_FEATURE_1_IBT property";
28442846
features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
28452847
}
2846-
if (ctx.arg.zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
2848+
if (ctx.arg.zPacPlt && !(hasValidPauthAbiCoreInfo ||
2849+
(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC))) {
28472850
Warn(ctx) << f
28482851
<< ": -z pac-plt: file does not have "
2849-
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property";
2852+
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid "
2853+
"PAuth core info present for this link job";
28502854
features |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
28512855
}
28522856
ctx.arg.andFeatures &= features;

lld/test/ELF/aarch64-feature-pac.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
# RUN: ld.lld %t.o %t2.o -z pac-plt %t.so -o %tpacplt.exe 2>&1 | FileCheck -DFILE=%t2.o --check-prefix WARN %s
8484

85-
# WARN: warning: [[FILE]]: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property
85+
# WARN: warning: [[FILE]]: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid PAuth core info present for this link job
8686

8787
# RUN: llvm-readelf -n %tpacplt.exe | FileCheck --check-prefix=PACPROP %s
8888
# RUN: llvm-readelf --dynamic-table %tpacplt.exe | FileCheck --check-prefix PACDYN2 %s

lld/test/ELF/aarch64-feature-pauth.s

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,53 @@
3333
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu no-info.s -o noinfo1.o
3434
# RUN: cp noinfo1.o noinfo2.o
3535
# RUN: not ld.lld -z pauth-report=error noinfo1.o tag1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix ERR5 %s
36-
# RUN: ld.lld -z pauth-report=warning noinfo1.o tag1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix WARN %s
36+
# RUN: ld.lld -z pauth-report=warning noinfo1.o tag1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix WARN1 %s
3737
# RUN: ld.lld -z pauth-report=none noinfo1.o tag1.o noinfo2.o --fatal-warnings -o /dev/null
3838

3939
# ERR5: error: noinfo1.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
4040
# ERR5-NEXT: error: noinfo2.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
41-
# WARN: warning: noinfo1.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
42-
# WARN-NEXT: warning: noinfo2.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
41+
# WARN1: warning: noinfo1.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
42+
# WARN1-NEXT: warning: noinfo2.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
43+
44+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu abi-tag-zero.s -o tag-zero.o
45+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func2.s -o func2.o
46+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o func3.o
47+
# RUN: ld.lld func3.o --shared -o func3.so
48+
# RUN: ld.lld tag1.o func2.o func3.so -z pac-plt --shared -o pacplt-nowarn --fatal-warnings
49+
# RUN: ld.lld tag-zero.o func2.o func3.so -z pac-plt --shared -o pacplt-warn 2>&1 | FileCheck --check-prefix WARN2 %s
50+
51+
# WARN2: warning: tag-zero.o: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid PAuth core info present for this link job
52+
# WARN2-NEXT: warning: func2.o: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid PAuth core info present for this link job
53+
54+
# RUN: llvm-readelf -d pacplt-nowarn | FileCheck --check-prefix=PACPLTTAG %s
55+
# RUN: llvm-readelf -d pacplt-warn | FileCheck --check-prefix=PACPLTTAG %s
56+
57+
# PACPLTTAG: 0x0000000070000003 (AARCH64_PAC_PLT)
58+
59+
# RUN: llvm-objdump -d pacplt-nowarn | FileCheck --check-prefix PACPLT -DA=10380 -DB=478 -DC=480 %s
60+
# RUN: llvm-objdump -d pacplt-warn | FileCheck --check-prefix PACPLT -DA=10390 -DB=488 -DC=490 %s
61+
62+
# PACPLT: Disassembly of section .text:
63+
# PACPLT: <func2>:
64+
# PACPLT-NEXT: bl 0x[[A]] <func3@plt>
65+
# PACPLT-NEXT: ret
66+
# PACPLT: Disassembly of section .plt:
67+
# PACPLT: <.plt>:
68+
# PACPLT-NEXT: stp x16, x30, [sp, #-0x10]!
69+
# PACPLT-NEXT: adrp x16, 0x30000 <func3+0x30000>
70+
# PACPLT-NEXT: ldr x17, [x16, #0x[[B]]]
71+
# PACPLT-NEXT: add x16, x16, #0x[[B]]
72+
# PACPLT-NEXT: br x17
73+
# PACPLT-NEXT: nop
74+
# PACPLT-NEXT: nop
75+
# PACPLT-NEXT: nop
76+
# PACPLT: <func3@plt>:
77+
# PACPLT-NEXT: adrp x16, 0x30000 <func3+0x30000>
78+
# PACPLT-NEXT: ldr x17, [x16, #0x[[C]]]
79+
# PACPLT-NEXT: add x16, x16, #0x[[C]]
80+
# PACPLT-NEXT: autia1716
81+
# PACPLT-NEXT: br x17
82+
# PACPLT-NEXT: nop
4383

4484
#--- abi-tag-short.s
4585

@@ -106,6 +146,18 @@
106146
.quad 42 // platform
107147
.quad 2 // version
108148

149+
#--- abi-tag-zero.s
150+
151+
.section ".note.gnu.property", "a"
152+
.long 4
153+
.long 24
154+
.long 5
155+
.asciz "GNU"
156+
.long 0xc0000001
157+
.long 16
158+
.quad 0 // platform
159+
.quad 0 // version
160+
109161
#--- no-info.s
110162

111163
## define _start to avoid missing entry warning and use --fatal-warnings to assert no diagnostic

0 commit comments

Comments
 (0)