r218064 - [X86, inlineasm] Check that the output size is correct for the given constraint.
Akira Hatanaka
ahatanaka at apple.com
Thu Sep 18 11:17:18 PDT 2014
Author: ahatanak
Date: Thu Sep 18 13:17:18 2014
New Revision: 218064
URL: http://llvm.org/viewvc/llvm-project?rev=218064&view=rev
Log:
[X86, inlineasm] Check that the output size is correct for the given constraint.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Sema/SemaStmtAsm.cpp
cfe/trunk/test/CodeGen/mmx-inline-asm-error.c
cfe/trunk/test/CodeGen/x86_32-inline-asm.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=218064&r1=218063&r2=218064&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep 18 13:17:18 2014
@@ -6051,6 +6051,8 @@ let CategoryName = "Inline Assembly Issu
def err_asm_bad_register_type : Error<"bad type for named register variable">;
def err_asm_invalid_input_size : Error<
"invalid input size for constraint '%0'">;
+ def err_asm_invalid_output_size : Error<
+ "invalid output size for constraint '%0'">;
def err_invalid_asm_cast_lvalue : Error<
"invalid use of a cast in a inline asm context requiring an l-value: "
"remove the cast or build with -fheinous-gnu-extensions">;
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=218064&r1=218063&r2=218064&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Sep 18 13:17:18 2014
@@ -577,6 +577,12 @@ public:
bool validateInputConstraint(ConstraintInfo *OutputConstraints,
unsigned NumOutputs,
ConstraintInfo &info) const;
+
+ virtual bool validateOutputSize(StringRef /*Constraint*/,
+ unsigned /*Size*/) const {
+ return true;
+ }
+
virtual bool validateInputSize(StringRef /*Constraint*/,
unsigned /*Size*/) const {
return true;
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=218064&r1=218063&r2=218064&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep 18 13:17:18 2014
@@ -1901,8 +1901,12 @@ public:
bool validateAsmConstraint(const char *&Name,
TargetInfo::ConstraintInfo &info) const override;
+ bool validateOutputSize(StringRef Constraint, unsigned Size) const override;
+
bool validateInputSize(StringRef Constraint, unsigned Size) const override;
+ virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const;
+
std::string convertConstraint(const char *&Constraint) const override;
const char *getClobbers() const override {
return "~{dirflag},~{fpsr},~{flags}";
@@ -3053,8 +3057,24 @@ X86TargetInfo::validateAsmConstraint(con
}
}
+bool X86TargetInfo::validateOutputSize(StringRef Constraint,
+ unsigned Size) const {
+ // Strip off constraint modifiers.
+ while (Constraint[0] == '=' ||
+ Constraint[0] == '+' ||
+ Constraint[0] == '&')
+ Constraint = Constraint.substr(1);
+
+ return validateOperandSize(Constraint, Size);
+}
+
bool X86TargetInfo::validateInputSize(StringRef Constraint,
unsigned Size) const {
+ return validateOperandSize(Constraint, Size);
+}
+
+bool X86TargetInfo::validateOperandSize(StringRef Constraint,
+ unsigned Size) const {
switch (Constraint[0]) {
default: break;
case 'y':
@@ -3124,8 +3144,8 @@ public:
if (RegNo == 1) return 2;
return -1;
}
- bool validateInputSize(StringRef Constraint,
- unsigned Size) const override {
+ bool validateOperandSize(StringRef Constraint,
+ unsigned Size) const override {
switch (Constraint[0]) {
default: break;
case 'R':
@@ -3142,7 +3162,7 @@ public:
return Size <= 64;
}
- return X86TargetInfo::validateInputSize(Constraint, Size);
+ return X86TargetInfo::validateOperandSize(Constraint, Size);
}
};
} // end anonymous namespace
Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=218064&r1=218063&r2=218064&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Thu Sep 18 13:17:18 2014
@@ -121,6 +121,20 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL
return StmtError();
OutputConstraintInfos.push_back(Info);
+
+ const Type *Ty = OutputExpr->getType().getTypePtr();
+
+ // If this is a dependent type, just continue. We don't know the size of a
+ // dependent type.
+ if (Ty->isDependentType())
+ continue;
+
+ unsigned Size = Context.getTypeSize(Ty);
+ if (!Context.getTargetInfo().validateOutputSize(Literal->getString(),
+ Size))
+ return StmtError(Diag(OutputExpr->getLocStart(),
+ diag::err_asm_invalid_output_size)
+ << Info.getConstraintStr());
}
SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
Modified: cfe/trunk/test/CodeGen/mmx-inline-asm-error.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mmx-inline-asm-error.c?rev=218064&r1=218063&r2=218064&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/mmx-inline-asm-error.c (original)
+++ cfe/trunk/test/CodeGen/mmx-inline-asm-error.c Thu Sep 18 13:17:18 2014
@@ -5,8 +5,8 @@ vec256 foo(vec256 in) {
vec256 out;
asm("something %0" : : "y"(in)); // expected-error {{invalid input size for constraint 'y'}}
- asm("something %0" : "=y"(out));
- asm("something %0, %0" : "+y"(out));
+ asm("something %0" : "=y"(out)); // expected-error {{invalid output size for constraint '=y'}}
+ asm("something %0, %0" : "+y"(out)); // expected-error {{invalid output size for constraint '+y'}}
return out;
}
Modified: cfe/trunk/test/CodeGen/x86_32-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-inline-asm.c?rev=218064&r1=218063&r2=218064&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/x86_32-inline-asm.c (original)
+++ cfe/trunk/test/CodeGen/x86_32-inline-asm.c Thu Sep 18 13:17:18 2014
@@ -43,4 +43,17 @@ int func1() {
__asm__ volatile("foo1 %0" : : "f" (val256)); // expected-error {{invalid input size for constraint 'f'}}
__asm__ volatile("foo1 %0" : : "t" (val256)); // expected-error {{invalid input size for constraint 't'}}
__asm__ volatile("foo1 %0" : : "u" (val256)); // expected-error {{invalid input size for constraint 'u'}}
+
+ __asm__ volatile("foo1 %0" : "=R" (val)); // expected-error {{invalid output size for constraint '=R'}}
+ __asm__ volatile("foo1 %0" : "=q" (val)); // expected-error {{invalid output size for constraint '=q'}}
+ __asm__ volatile("foo1 %0" : "=Q" (val)); // expected-error {{invalid output size for constraint '=Q'}}
+ __asm__ volatile("foo1 %0" : "=a" (val)); // expected-error {{invalid output size for constraint '=a'}}
+ __asm__ volatile("foo1 %0" : "=b" (val)); // expected-error {{invalid output size for constraint '=b'}}
+ __asm__ volatile("foo1 %0" : "=c" (val)); // expected-error {{invalid output size for constraint '=c'}}
+ __asm__ volatile("foo1 %0" : "=d" (val)); // expected-error {{invalid output size for constraint '=d'}}
+ __asm__ volatile("foo1 %0" : "=S" (val)); // expected-error {{invalid output size for constraint '=S'}}
+ __asm__ volatile("foo1 %0" : "=D" (val)); // expected-error {{invalid output size for constraint '=D'}}
+ __asm__ volatile("foo1 %0" : "=A" (val128)); // expected-error {{invalid output size for constraint '=A'}}
+ __asm__ volatile("foo1 %0" : "=t" (val256)); // expected-error {{invalid output size for constraint '=t'}}
+ __asm__ volatile("foo1 %0" : "=u" (val256)); // expected-error {{invalid output size for constraint '=u'}}
}
More information about the cfe-commits
mailing list