зеркало из https://github.com/microsoft/clang-1.git
Check that the clobber registers are valid.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44311 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
646b261662
Коммит
6fa9086043
|
@ -14,8 +14,9 @@
|
||||||
#include "clang/Basic/TargetInfo.h"
|
#include "clang/Basic/TargetInfo.h"
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "clang/AST/Builtins.h"
|
#include "clang/AST/Builtins.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
|
||||||
#include "llvm/ADT/APFloat.h"
|
#include "llvm/ADT/APFloat.h"
|
||||||
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
|
@ -270,6 +271,46 @@ const char *TargetInfo::getVAListDeclaration() const {
|
||||||
/// is a valid register name according to GCC. This is used by Sema for
|
/// is a valid register name according to GCC. This is used by Sema for
|
||||||
/// inline asm statements.
|
/// inline asm statements.
|
||||||
bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
|
bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
|
||||||
// FIXME: Implement this.
|
const char * const *Names;
|
||||||
|
unsigned NumNames;
|
||||||
|
|
||||||
|
// Get rid of any register prefix.
|
||||||
|
if (Name[0] == '%' || Name[0] == '#')
|
||||||
|
Name++;
|
||||||
|
|
||||||
|
if (strcmp(Name, "memory") == 0 ||
|
||||||
|
strcmp(Name, "cc") == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
PrimaryTarget->getGCCRegNames(Names, NumNames);
|
||||||
|
|
||||||
|
// If we have a number it maps to an entry in the register name array.
|
||||||
|
if (isdigit(Name[0])) {
|
||||||
|
char *End;
|
||||||
|
int n = (int)strtol(Name, &End, 0);
|
||||||
|
if (*End == 0)
|
||||||
|
return n >= 0 && (unsigned)n < NumNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check register names.
|
||||||
|
for (unsigned i = 0; i < NumNames; i++) {
|
||||||
|
if (strcmp(Name, Names[i]) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now check aliases.
|
||||||
|
const TargetInfoImpl::GCCRegAlias *Aliases;
|
||||||
|
unsigned NumAliases;
|
||||||
|
|
||||||
|
PrimaryTarget->getGCCRegAliases(Aliases, NumAliases);
|
||||||
|
for (unsigned i = 0; i < NumAliases; i++) {
|
||||||
|
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
|
||||||
|
if (!Aliases[i].Aliases[j])
|
||||||
|
break;
|
||||||
|
if (strcmp(Aliases[i].Aliases[j], Name) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
#include "clang/AST/Expr.h"
|
#include "clang/AST/Expr.h"
|
||||||
#include "clang/AST/Stmt.h"
|
#include "clang/AST/Stmt.h"
|
||||||
#include "clang/Parse/Scope.h"
|
#include "clang/Parse/Scope.h"
|
||||||
|
#include "clang/Basic/TargetInfo.h"
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "clang/Basic/LangOptions.h"
|
#include "clang/Basic/LangOptions.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) {
|
Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) {
|
||||||
|
@ -691,6 +693,25 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the clobbers are valid.
|
||||||
|
for (unsigned i = 0; i < NumClobbers; i++) {
|
||||||
|
StringLiteral *Literal = cast<StringLiteral>((Expr *)Clobbers[i]);
|
||||||
|
assert(!Literal->isWide() && "Clobber strings should not be wide!");
|
||||||
|
|
||||||
|
llvm::SmallString<16> Clobber(Literal->getStrData(),
|
||||||
|
Literal->getStrData() +
|
||||||
|
Literal->getByteLength());
|
||||||
|
|
||||||
|
if (!Context.Target.isValidGCCRegisterName(Clobber.c_str())) {
|
||||||
|
Diag(Literal->getLocStart(),
|
||||||
|
diag::err_unknown_register_name_in_asm,
|
||||||
|
Clobber.c_str());
|
||||||
|
|
||||||
|
// FIXME: We currently leak memory here.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new AsmStmt(AsmLoc,
|
return new AsmStmt(AsmLoc,
|
||||||
IsVolatile,
|
IsVolatile,
|
||||||
NumOutputs,
|
NumOutputs,
|
||||||
|
|
|
@ -793,6 +793,8 @@ DIAG(err_invalid_lvalue_in_asm_output, ERROR,
|
||||||
"invalid lvalue in asm output")
|
"invalid lvalue in asm output")
|
||||||
DIAG(err_invalid_type_in_asm_input, ERROR,
|
DIAG(err_invalid_type_in_asm_input, ERROR,
|
||||||
"invalid type '%0' in asm input")
|
"invalid type '%0' in asm input")
|
||||||
|
DIAG(err_unknown_register_name_in_asm, ERROR,
|
||||||
|
"unknown register name '%0' in asm")
|
||||||
|
|
||||||
// CHECK: printf format string errors
|
// CHECK: printf format string errors
|
||||||
DIAG(warn_printf_not_string_constant, WARNING,
|
DIAG(warn_printf_not_string_constant, WARNING,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// RUN: clang %s -verify -fsyntax-only
|
// RUN: clang %s -arch=i386 -verify -fsyntax-only
|
||||||
|
|
||||||
void
|
void
|
||||||
f()
|
f()
|
||||||
|
@ -12,3 +12,16 @@ f()
|
||||||
asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}}
|
asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clobbers()
|
||||||
|
{
|
||||||
|
asm ("nop" : : : "ax", "#ax", "%ax");
|
||||||
|
asm ("nop" : : : "eax", "rax", "ah", "al");
|
||||||
|
asm ("nop" : : : "0", "%0", "#0");
|
||||||
|
asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}}
|
||||||
|
asm ("nop" : : : "52");
|
||||||
|
asm ("nop" : : : "53"); // expected-error {{unknown register name '53' in asm}}
|
||||||
|
asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
|
||||||
|
asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче