[cfe-commits] r166647 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Basic/TargetInfo.h lib/Basic/Targets.cpp lib/Sema/SemaStmtAsm.cpp test/Misc/warning-flags.c
Eli Friedman
eli.friedman at gmail.com
Wed Oct 24 17:18:11 PDT 2012
On Wed, Oct 24, 2012 at 5:05 PM, Bill Wendling <isanbard at gmail.com> wrote:
> Author: void
> Date: Wed Oct 24 19:05:55 2012
> New Revision: 166647
>
> URL: http://llvm.org/viewvc/llvm-project?rev=166647&view=rev
> Log:
> Add some support for diagnosing possibly mismatched constraint, type size and
> modifiers. (From an idea by Eric...)
> <rdar://problem/12284092>
>
> 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/Misc/warning-flags.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=166647&r1=166646&r2=166647&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Oct 24 19:05:55 2012
> @@ -5146,6 +5146,9 @@
> "invalid use of a cast in a inline asm context requiring an l-value: "
> "accepted due to -fheinous-gnu-extensions, but clang may remove support "
> "for this in the future">;
> + def warn_mismatched_size_modifier : Warning<
> + "the size being stored may not be the size intended, use a modifier to "
> + "specify the size">;
>
> def err_inline_ms_asm_parsing : Error<"%0">;
> }
>
> Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=166647&r1=166646&r2=166647&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
> +++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Oct 24 19:05:55 2012
> @@ -517,6 +517,11 @@
> bool validateInputConstraint(ConstraintInfo *OutputConstraints,
> unsigned NumOutputs,
> ConstraintInfo &info) const;
> + virtual bool validateConstraintModifier(StringRef /*Constraint*/,
> + const char /*Modifier*/,
> + unsigned /*Size*/) const {
> + return true;
> + }
> bool resolveSymbolicName(const char *&Name,
> ConstraintInfo *OutputConstraints,
> unsigned NumOutputs, unsigned &Index) const;
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=166647&r1=166646&r2=166647&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Oct 24 19:05:55 2012
> @@ -3315,6 +3315,29 @@
> }
> return R;
> }
> + virtual bool validateConstraintModifier(StringRef Constraint,
> + const char Modifier,
> + unsigned Size) const {
> + // Strip off constraint modifiers.
> + while (Constraint[0] == '=' ||
> + Constraint[0] == '+' ||
> + Constraint[0] == '&')
> + Constraint = Constraint.substr(1);
> +
> + switch (Constraint[0]) {
> + default: break;
> + case 'r': {
> + switch (Modifier) {
> + default: return Size == 32;
> + case 'q':
> + // A register of size 32 cannot fit a vector type.
> + return false;
> + }
> + }
> + }
> +
> + return true;
> + }
> virtual const char *getClobbers() const {
> // FIXME: Is this really right?
> return "";
>
> Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=166647&r1=166646&r2=166647&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Wed Oct 24 19:05:55 2012
> @@ -208,6 +208,54 @@
> return StmtError();
> }
>
> + // Validate constraints and modifiers.
> + for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
> + GCCAsmStmt::AsmStringPiece &Piece = Pieces[i];
> + if (!Piece.isOperand()) continue;
> +
> + // Look for the correct constraint index.
> + unsigned Idx = 0;
> + unsigned ConstraintIdx = 0;
> + for (unsigned i = 0, e = NS->getNumOutputs(); i != e; ++i, ++ConstraintIdx) {
> + TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
> + if (Idx == Piece.getOperandNo())
> + break;
> + ++Idx;
> +
> + if (Info.isReadWrite()) {
> + if (Idx == Piece.getOperandNo())
> + break;
> + ++Idx;
> + }
> + }
> +
> + for (unsigned i = 0, e = NS->getNumInputs(); i != e; ++i, ++ConstraintIdx) {
> + TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
> + if (Idx == Piece.getOperandNo())
> + break;
> + ++Idx;
> +
> + if (Info.isReadWrite()) {
> + if (Idx == Piece.getOperandNo())
> + break;
> + ++Idx;
> + }
> + }
> +
> + // Now that we have the right indexes go ahead and check.
> + StringLiteral *Literal = Constraints[ConstraintIdx];
> + const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr();
> + if (Ty->isDependentType() || Ty->isIncompleteType())
> + continue;
> +
> + unsigned Size = Context.getTypeSize(Ty);
> + if (!Context.getTargetInfo()
> + .validateConstraintModifier(Literal->getString(),
> + Piece.getModifier(), Size))
> + Diag(Exprs[ConstraintIdx]->getLocStart(),
> + diag::warn_mismatched_size_modifier);
> + }
> +
> // Validate tied input operands for type mismatches.
> for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
> TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
>
> Modified: cfe/trunk/test/Misc/warning-flags.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=166647&r1=166646&r2=166647&view=diff
> ==============================================================================
> --- cfe/trunk/test/Misc/warning-flags.c (original)
> +++ cfe/trunk/test/Misc/warning-flags.c Wed Oct 24 19:05:55 2012
> @@ -18,7 +18,7 @@
>
> The list of warnings below should NEVER grow. It should gradually shrink to 0.
>
> -CHECK: Warnings without flags (154):
> +CHECK: Warnings without flags (155):
"The list of warnings below should NEVER grow"
-Eli
More information about the cfe-commits
mailing list