Split out logic for valid clobbers and valid inline asm registers.

Fixes rdar://9281377

llvm-svn: 134016
This commit is contained in:
Eric Christopher 2011-06-28 18:20:53 +00:00
parent b26d578b41
commit fd9a5f4f66
5 changed files with 19 additions and 5 deletions

View File

@ -303,6 +303,11 @@ public:
/// __builtin_va_list, which is target-specific.
virtual const char *getVAListDeclaration() const = 0;
/// isValidClobber - Returns whether the passed in string is
/// a valid clobber in an inline asm statement. This is used by
/// Sema.
bool isValidClobber(llvm::StringRef Name) const;
/// isValidGCCRegisterName - Returns whether the passed in string
/// is a valid register name according to GCC. This is used by Sema for
/// inline asm statements.

View File

@ -181,6 +181,14 @@ static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) {
return Name;
}
/// isValidClobber - Returns whether the passed in string is
/// a valid clobber in an inline asm statement. This is used by
/// Sema.
bool TargetInfo::isValidClobber(llvm::StringRef Name) const {
return (isValidGCCRegisterName(Name) ||
Name == "memory" || Name == "cc");
}
/// isValidGCCRegisterName - Returns whether the passed in string
/// is a valid register name according to GCC. This is used by Sema for
/// inline asm statements.
@ -194,9 +202,6 @@ bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const {
// Get rid of any register prefix.
Name = removeGCCRegisterPrefix(Name);
if (Name == "memory" || Name == "cc")
return true;
getGCCRegNames(Names, NumNames);
// If we have a number it maps to an entry in the register name array.

View File

@ -1558,6 +1558,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) {
llvm::StringRef Clobber = S.getClobber(i)->getString();
if (Clobber != "memory" && Clobber != "cc")
Clobber = Target.getNormalizedGCCRegisterName(Clobber);
if (i != 0 || NumConstraints != 0)

View File

@ -1990,7 +1990,7 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
llvm::StringRef Clobber = Literal->getString();
if (!Context.Target.isValidGCCRegisterName(Clobber))
if (!Context.Target.isValidClobber(Clobber))
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_unknown_register_name) << Clobber);
}
@ -2350,4 +2350,3 @@ Sema::ActOnSEHFinallyBlock(SourceLocation Loc,
assert(Block);
return Owned(SEHFinallyStmt::Create(Context,Loc,Block));
}

View File

@ -113,3 +113,7 @@ void test11(void) {
_Bool b;
asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
}
void test12(void) {
register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}}
}