Skip to content

Commit 29d99b2

Browse files
- Add warnings to clang for unsupported cases where unwinding is not possible
because of streaming-mode changes without SVE available. - Fixed incorrect labels in sme-vg-to-stack.ll
1 parent 83dcbcc commit 29d99b2

File tree

8 files changed

+101
-34
lines changed

8 files changed

+101
-34
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ def MultiGPU: DiagGroup<"multi-gpu">;
14121412
// libc and the CRT to be skipped.
14131413
def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
14141414

1415-
// A warning group related to AArch64 SME function attribues.
1415+
// A warning group related to AArch64 SME function attributes.
14161416
def AArch64SMEAttributes : DiagGroup<"aarch64-sme-attributes">;
14171417

14181418
// A warning group for things that will change semantics in the future.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,6 +3730,12 @@ def warn_gnu_inline_cplusplus_without_extern : Warning<
37303730
"'gnu_inline' attribute without 'extern' in C++ treated as externally"
37313731
" available, this changed in Clang 10">,
37323732
InGroup<DiagGroup<"gnu-inline-cpp-without-extern">>;
3733+
def warn_sme_streaming_mode_change_no_sve : Warning<
3734+
"function requires a streaming-mode change, unwinding is not possible without 'sve'">,
3735+
InGroup<AArch64SMEAttributes>;
3736+
def warn_sme_locally_streaming_no_sve : Warning<
3737+
"unwinding is not possible for locally-streaming functions without 'sve'">,
3738+
InGroup<AArch64SMEAttributes>;
37333739
def err_attribute_vecreturn_only_vector_member : Error<
37343740
"the vecreturn attribute can only be used on a class or structure with one member, which must be a vector">;
37353741
def err_attribute_vecreturn_only_pod_record : Error<

clang/lib/Sema/SemaChecking.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,9 @@ bool Sema::ParseSVEImmChecks(
35053505
}
35063506

35073507
static ArmStreamingType getArmStreamingFnType(const FunctionDecl *FD) {
3508+
const QualType QT = FD->getType();
3509+
if (QT.isNull())
3510+
return ArmNonStreaming;
35083511
if (FD->hasAttr<ArmLocallyStreamingAttr>())
35093512
return ArmStreaming;
35103513
if (const Type *Ty = FD->getType().getTypePtrOrNull()) {
@@ -7978,8 +7981,11 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
79787981
// If the callee has an AArch64 SME attribute to indicate that it is an
79797982
// __arm_streaming function, then the caller requires SME to be available.
79807983
FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo();
7981-
if (ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask) {
7982-
if (auto *CallerFD = dyn_cast<FunctionDecl>(CurContext)) {
7984+
auto *CallerFD = dyn_cast<FunctionDecl>(CurContext);
7985+
bool IsCalleeStreaming =
7986+
ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
7987+
if (IsCalleeStreaming) {
7988+
if (CallerFD) {
79837989
llvm::StringMap<bool> CallerFeatureMap;
79847990
Context.getFunctionFeatureMap(CallerFeatureMap, CallerFD);
79857991
if (!CallerFeatureMap.contains("sme"))
@@ -7989,18 +7995,28 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
79897995
}
79907996
}
79917997

7992-
// If the call requires a streaming-mode change and has scalable vector
7993-
// arguments or return values, then warn the user that the streaming and
7994-
// non-streaming vector lengths may be different.
7995-
const auto *CallerFD = dyn_cast<FunctionDecl>(CurContext);
7996-
if (CallerFD && (!FD || !FD->getBuiltinID()) && AnyScalableArgsOrRet) {
7997-
bool IsCalleeStreaming =
7998-
ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
7998+
if (CallerFD && (!FD || !FD->getBuiltinID())) {
79997999
bool IsCalleeStreamingCompatible =
80008000
ExtInfo.AArch64SMEAttributes &
80018001
FunctionType::SME_PStateSMCompatibleMask;
80028002
ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
8003-
if (!IsCalleeStreamingCompatible &&
8003+
8004+
// SME functions may require SVE to be available for unwinding, as the
8005+
// value of VG needs to be preserved across streaming-mode changes.
8006+
if (!Context.getTargetInfo().hasFeature("sve")) {
8007+
if (CallerFD->hasAttr<ArmLocallyStreamingAttr>())
8008+
Diag(Loc, diag::warn_sme_locally_streaming_no_sve);
8009+
8010+
if ((CallerFnType == ArmStreaming ||
8011+
CallerFnType == ArmStreamingCompatible) &&
8012+
(!IsCalleeStreaming && !IsCalleeStreamingCompatible))
8013+
Diag(Loc, diag::warn_sme_streaming_mode_change_no_sve);
8014+
}
8015+
8016+
// If the call requires a streaming-mode change and has scalable vector
8017+
// arguments or return values, then warn the user that the streaming and
8018+
// non-streaming vector lengths may be different.
8019+
if (AnyScalableArgsOrRet && !IsCalleeStreamingCompatible &&
80048020
(CallerFnType == ArmStreamingCompatible ||
80058021
((CallerFnType == ArmStreaming) ^ IsCalleeStreaming)))
80068022
Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming);

clang/test/CodeGen/aarch64-sme-inline-streaming-attrs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_NONE %s
2-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_COMPATIBLE %s
3-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_STREAMING %s
4-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_LOCALLY %s
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_NONE %s
2+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_COMPATIBLE %s
3+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_STREAMING %s
4+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_LOCALLY %s
55

66
#define __ai __attribute__((always_inline))
77
__ai void inlined_fn(void) {}

clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme \
2-
// RUN: -S -disable-O0-optnone -Werror -emit-llvm -o - %s \
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve \
2+
// RUN: -target-feature +sme -S -disable-O0-optnone -Werror -emit-llvm -o - %s \
33
// RUN: | opt -S -passes=mem2reg \
44
// RUN: | opt -S -passes=inline \
55
// RUN: | FileCheck %s
@@ -278,18 +278,18 @@ int test_variadic_template() __arm_inout("za") {
278278
preserves_za_decl);
279279
}
280280

281-
// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
282-
// CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
283-
// CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
284-
// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
285-
// CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
286-
// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
287-
// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
288-
// CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
289-
// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
290-
// CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
291-
// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
292-
// CHECK: attributes #[[NORMAL_DEF]] = { mustprogress noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
281+
// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
282+
// CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
283+
// CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
284+
// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
285+
// CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
286+
// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
287+
// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
288+
// CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
289+
// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
290+
// CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
291+
// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
292+
// CHECK: attributes #[[NORMAL_DEF]] = { mustprogress noinline nounwind vscale_range(1,16) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
293293
// CHECK: attributes #[[SM_ENABLED_CALL]] = { "aarch64_pstate_sm_enabled" }
294294
// CHECK: attributes #[[SM_COMPATIBLE_CALL]] = { "aarch64_pstate_sm_compatible" }
295295
// CHECK: attributes #[[SM_BODY_CALL]] = { "aarch64_pstate_sm_body" }

clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void non_streaming_def(void (*streaming_fn_ptr)(void) __arm_streaming,
3838
void streaming_compatible_def2(void (*streaming_fn_ptr)(void) __arm_streaming,
3939
void (*streaming_compatible_fn_ptr)(void) __arm_streaming_compatible)
4040
__arm_streaming_compatible {
41-
non_streaming_decl(); // OK
41+
non_streaming_decl(); // expected-warning {{function requires a streaming-mode change, unwinding is not possible without 'sve'}}
4242
streaming_compatible_decl(); // OK
4343
streaming_compatible_fn_ptr(); // OK
4444
streaming_decl(); // expected-error {{call to a streaming function requires 'sme'}}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme \
2+
// RUN: -target-feature -sve -Waarch64-sme-attributes -fsyntax-only -verify %s
3+
4+
// REQUIRES: aarch64-registered-target
5+
6+
#include "arm_sme.h"
7+
8+
int non_streaming_decl(void);
9+
int streaming_decl(void) __arm_streaming;
10+
int streaming_compatible_decl(void) __arm_streaming_compatible;
11+
12+
// Streaming-mode changes which would require spilling VG, unsupported without SVE
13+
14+
int streaming_caller_no_sve(void) __arm_streaming {
15+
// expected-warning@+1 {{function requires a streaming-mode change, unwinding is not possible without 'sve'}}
16+
return non_streaming_decl();
17+
}
18+
19+
int sc_caller_non_streaming_callee(void) __arm_streaming_compatible {
20+
// expected-warning@+1 {{function requires a streaming-mode change, unwinding is not possible without 'sve'}}
21+
return non_streaming_decl();
22+
}
23+
24+
__arm_locally_streaming int locally_streaming_no_sve(void) {
25+
// expected-warning@+1 {{unwinding is not possible for locally-streaming functions without 'sve'}}
26+
return streaming_decl();
27+
}
28+
29+
// No warnings expected
30+
31+
int normal_caller_streaming_callee(void) {
32+
return streaming_decl();
33+
}
34+
35+
int normal_caller_streaming_compatible_callee(void) {
36+
return streaming_compatible_decl();
37+
}
38+
39+
int sc_caller_streaming_callee(void) __arm_streaming_compatible {
40+
return streaming_decl();
41+
}
42+
43+
int sc_caller_sc_callee(void) __arm_streaming_compatible {
44+
return streaming_compatible_decl();
45+
}

llvm/test/CodeGen/AArch64/sme-vg-to-stack.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,15 +1030,15 @@ define void @streaming_compatible_no_sve() #4 {
10301030
; NO-SVE-CHECK-NEXT: .cfi_offset b15, -96
10311031
; NO-SVE-CHECK-NEXT: bl __arm_sme_state
10321032
; NO-SVE-CHECK-NEXT: and x19, x0, #0x1
1033-
; NO-SVE-CHECK-NEXT: tbnz w19, #0, .LBB6_2
1033+
; NO-SVE-CHECK-NEXT: tbnz w19, #0, .LBB8_2
10341034
; NO-SVE-CHECK-NEXT: // %bb.1:
10351035
; NO-SVE-CHECK-NEXT: smstart sm
1036-
; NO-SVE-CHECK-NEXT: .LBB6_2:
1036+
; NO-SVE-CHECK-NEXT: .LBB8_2:
10371037
; NO-SVE-CHECK-NEXT: bl streaming_callee
1038-
; NO-SVE-CHECK-NEXT: tbnz w19, #0, .LBB6_4
1038+
; NO-SVE-CHECK-NEXT: tbnz w19, #0, .LBB8_4
10391039
; NO-SVE-CHECK-NEXT: // %bb.3:
10401040
; NO-SVE-CHECK-NEXT: smstop sm
1041-
; NO-SVE-CHECK-NEXT: .LBB6_4:
1041+
; NO-SVE-CHECK-NEXT: .LBB8_4:
10421042
; NO-SVE-CHECK-NEXT: .cfi_def_cfa wsp, 96
10431043
; NO-SVE-CHECK-NEXT: ldp x29, x30, [sp, #64] // 16-byte Folded Reload
10441044
; NO-SVE-CHECK-NEXT: ldr x19, [sp, #80] // 8-byte Folded Reload

0 commit comments

Comments
 (0)