Skip to content

Commit 9780af3

Browse files
committed
[Clang] Fix crash for incompatible types in inline assembly
1 parent 7787328 commit 9780af3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clang/lib/Sema/SemaStmtAsm.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,22 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
664664
SmallerValueMentioned |= OutSize < InSize;
665665
}
666666

667+
// If the input is an integer register while the output is floating point,
668+
// there is no way they can work together.
669+
bool FPBoundToInt = false;
670+
if (InputDomain != AD_FP && OutputDomain == AD_FP) {
671+
FPBoundToInt = true;
672+
}
673+
if (InputDomain == AD_FP && OutputDomain != AD_FP) {
674+
FPBoundToInt = true;
675+
}
676+
667677
// If the smaller value wasn't mentioned in the asm string, and if the
668678
// output was a register, just extend the shorter one to the size of the
669679
// larger one.
670-
if (!SmallerValueMentioned && InputDomain != AD_Other &&
680+
if (!SmallerValueMentioned && !FPBoundToInt && InputDomain != AD_Other &&
671681
OutputConstraintInfos[TiedTo].allowsRegister()) {
682+
672683
// FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
673684
// crash when the size larger than the register size. So we limit it here.
674685
if (OutTy->isStructureType() &&

clang/test/Sema/asm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,9 @@ void test19(long long x)
365365
// FIXME: This case should be supported by codegen, but it fails now.
366366
asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'st_size128' (aka 'struct _st_size128') matching output with type 'long long'}}
367367
}
368+
369+
// PR119098
370+
void test20(char x) {
371+
double value;
372+
asm ("fabs" : "=t" (value): "0" (x)); // expected-error {{unsupported inline asm: input with type 'char' matching output with type 'double'}}
373+
}

0 commit comments

Comments
 (0)