Skip to content

Commit fdc8e5a

Browse files
v01dXYZv01dxyz
andauthored
[Clang][AArch64] Fix typo with colon-separated syntax for system registers (#105608)
The range for Op0 was set to 1 instead of 3. The description of e493f17 visually explains the encoding of implementation-defined system registers. https://github.com/llvm/llvm-project/blob/796787d07c30cb9448e1f9ff3f3da06c2fc96ccd/llvm/lib/Target/AArch64/AArch64SystemOperands.td#L658-L674 Gobolt: https://godbolt.org/z/WK9PqPvGE Co-authored-by: v01dxyz <[email protected]>
1 parent 502385c commit fdc8e5a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

clang/lib/Sema/SemaARM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,16 @@ bool SemaARM::BuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall,
249249
}
250250
}
251251

252-
SmallVector<int, 5> Ranges;
252+
SmallVector<int, 5> FieldBitWidths;
253253
if (FiveFields)
254-
Ranges.append({IsAArch64Builtin ? 1 : 15, 7, 15, 15, 7});
254+
FieldBitWidths.append({IsAArch64Builtin ? 2 : 4, 3, 4, 4, 3});
255255
else
256-
Ranges.append({15, 7, 15});
256+
FieldBitWidths.append({4, 3, 4});
257257

258258
for (unsigned i = 0; i < Fields.size(); ++i) {
259259
int IntField;
260260
ValidString &= !Fields[i].getAsInteger(10, IntField);
261-
ValidString &= (IntField >= 0 && IntField <= Ranges[i]);
261+
ValidString &= (IntField >= 0 && IntField < (1 << FieldBitWidths[i]));
262262
}
263263

264264
if (!ValidString)

clang/test/Sema/aarch64-special-register.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ unsigned long rsr64_6(void) {
116116
return __builtin_arm_rsr64("0:1:16:16:2"); //expected-error {{invalid special register for builtin}}
117117
}
118118

119+
void rsr64_7(unsigned long *r) {
120+
// The following three instructions should produce the same assembly.
121+
r[0] = __builtin_arm_rsr64("ICC_CTLR_EL3");
122+
r[1] = __builtin_arm_rsr64("s3_6_c12_c12_4");
123+
r[2] = __builtin_arm_rsr64("3:6:12:12:4");
124+
}
125+
119126
__uint128_t rsr128_3(void) {
120127
return __builtin_arm_rsr128("0:1:2"); //expected-error {{invalid special register for builtin}}
121128
}

0 commit comments

Comments
 (0)