-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[msan] Convert target("aarch64.svcount") from compile-time crash to MSan false negatives #165028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,7 @@ static const Align kMinOriginAlignment = Align(4); | |
| static const Align kShadowTLSAlignment = Align(8); | ||
|
|
||
| // These constants must be kept in sync with the ones in msan.h. | ||
| // TODO: increase size to match SVE/SVE2/SME/SME2 limits | ||
| static const unsigned kParamTLSSize = 800; | ||
| static const unsigned kRetvalTLSSize = 800; | ||
|
|
||
|
|
@@ -1544,6 +1545,27 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { | |
| } | ||
| } | ||
|
|
||
| static bool isAArch64SVCount(Type *Ty) { | ||
| if (!isa<TargetExtType>(Ty)) | ||
| return false; | ||
|
|
||
| TargetExtType* TTy = cast<TargetExtType>(Ty); | ||
| return TTy->getName() == "aarch64.svcount"; | ||
| } | ||
|
|
||
| // This is intended to match the "AArch64 Predicate-as-Counter Type" (aka | ||
| // 'target("aarch64.svcount")', but not e.g., <vscale x 4 x i32>. | ||
| static bool isScalableNonVectorType(Type *Ty) { | ||
| if (!isAArch64SVCount(Ty)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The not branch will happen if a similar predicate is introduced for RISC-V, Loongaarch, etc. Adding an assert would break them unnecessarily. OTOH at the moment I am (willfully) unaware of such a predicate on other platforms; hence, the log message for debugging because it is somewhat unexpected. |
||
| LLVM_DEBUG(dbgs() << "isScalableNonVectorType: Unexpected type " << *Ty << "\n"); | ||
|
|
||
| return Ty->isScalableTy() && !isa<VectorType>(Ty); | ||
| } | ||
|
|
||
| static bool isScalableNonVectorType(Instruction *I) { | ||
|
||
| return isScalableNonVectorType(I->getType()); | ||
| } | ||
|
|
||
| void materializeChecks() { | ||
| #ifndef NDEBUG | ||
| // For assert below. | ||
|
|
@@ -1672,6 +1694,11 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { | |
| LLVM_DEBUG(dbgs() << "getShadowTy: " << *ST << " ===> " << *Res << "\n"); | ||
| return Res; | ||
| } | ||
| if (isScalableNonVectorType(OrigTy)){ | ||
| LLVM_DEBUG(dbgs() << "getShadowTy: Scalable non-vector type: " << *OrigTy << "\n"); | ||
| return OrigTy; | ||
| } | ||
|
|
||
| uint32_t TypeSize = DL.getTypeSizeInBits(OrigTy); | ||
| return IntegerType::get(*MS.C, TypeSize); | ||
| } | ||
|
|
@@ -2185,8 +2212,14 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { | |
| << *OrigIns << "\n"); | ||
| return; | ||
| } | ||
| #ifndef NDEBUG | ||
|
|
||
| Type *ShadowTy = Shadow->getType(); | ||
| if (isScalableNonVectorType(ShadowTy)) { | ||
| LLVM_DEBUG(dbgs() << "Skipping check of scalable non-vector " << *Shadow | ||
| << " before " << *OrigIns << "\n"); | ||
| return; | ||
| } | ||
| #ifndef NDEBUG | ||
| assert((isa<IntegerType>(ShadowTy) || isa<VectorType>(ShadowTy) || | ||
| isa<StructType>(ShadowTy) || isa<ArrayType>(ShadowTy)) && | ||
| "Can only insert checks for integer, vector, and aggregate shadow " | ||
|
|
@@ -6972,6 +7005,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { | |
| // an extra "select". This results in much more compact IR. | ||
| // Sa = select Sb, poisoned, (select b, Sc, Sd) | ||
| Sa1 = getPoisonedShadow(getShadowTy(I.getType())); | ||
| } else if (isScalableNonVectorType(&I)) { | ||
| // This is intended to handle target("aarch64.svcount"), which can't be | ||
| // handled in the else branch because of incompatibility with CreateXor | ||
| // ("The supported LLVM operations on this type are limited to load, | ||
| // store, phi, select and alloca instructions"). | ||
|
|
||
| // TODO: this currently underapproximates. Use Arm SVE EOR in the else | ||
| // branch as needed instead. | ||
| Sa1 = getCleanShadow(getShadowTy(I.getType())); | ||
| } else { | ||
| // Sa = select Sb, [ (c^d) | Sc | Sd ], [ b ? Sc : Sd ] | ||
| // If Sb (condition is poisoned), look for bits in c and d that are equal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
| ; RUN: opt -S -passes=msan -mattr=+sme -o - %s | ||
|
|
||
| ; XFAIL: * | ||
| ; RUN: opt -S -passes=msan -mattr=+sme -o - %s | FileCheck %s | ||
|
|
||
| ; Forked from llvm/test/CodeGen/AArch64/sme-aarch64-svcount.ll | ||
| ; Manually minimized to show MSan leads to a compiler crash | ||
|
|
||
| target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" | ||
| target triple = "aarch64--linux-android9001" | ||
|
|
||
| define target("aarch64.svcount") @test_return_arg1(target("aarch64.svcount") %arg0, target("aarch64.svcount") %arg1) nounwind { | ||
| ; CHECK-LABEL: @test_return_arg1( | ||
| ; CHECK-NEXT: call void @llvm.donothing() | ||
| ; CHECK-NEXT: store target("aarch64.svcount") zeroinitializer, ptr @__msan_retval_tls, align 8 | ||
| ; CHECK-NEXT: ret target("aarch64.svcount") [[ARG1:%.*]] | ||
| ; | ||
| ret target("aarch64.svcount") %arg1 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced