Skip to content

Commit

Permalink
Error out for unsupported vector types in function bodies
Browse files Browse the repository at this point in the history
Now that we've added the length 8 and 16 vector types again,
we should emit errors when they are used inside function bodies.
  • Loading branch information
dneto0 committed Aug 2, 2017
1 parent 568bba6 commit 099ce2a
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tools/driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/TargetInfo.h>
#include <clang/CodeGen/CodeGenAction.h>
#include <clang/Frontend/CompilerInstance.h>
Expand Down Expand Up @@ -67,11 +68,37 @@ struct ExtraValidationConsumer final : public ASTConsumer {
return true;
}

// This will be used to check the inside of function bodies.
class DeclVisitor : public RecursiveASTVisitor<DeclVisitor> {
private:
ExtraValidationConsumer &consumer;

public:
explicit DeclVisitor(ExtraValidationConsumer &VC) : consumer(VC) {}

// Visits a declaration. Emits a diagnostic and returns false if the
// declaration represents an unsupported vector value or vector type.
// Otherwise returns true.
bool VisitDecl(Decl *D) {
// Looking at the Decl class hierarchy, it seems ValueDecl and TypeDecl
// are the only two that might represent an unsupported vector type.
if (auto *VD = dyn_cast<ValueDecl>(D)) {
return consumer.IsSupportedType(VD->getType(), D->getSourceRange());
} else if (auto *TD = dyn_cast<TypeDecl>(D)) {
QualType DefinedType = TD->getASTContext().getTypeDeclType(TD);
return consumer.IsSupportedType(DefinedType, TD->getSourceRange());
}
return true;
}
};

DeclVisitor Visitor;

public:
explicit ExtraValidationConsumer(CompilerInstance &Instance,
llvm::StringRef InFile)
: Instance(Instance), InFile(InFile),
CustomDiagnosticsIDMap(CustomDiagnosticTotal) {
CustomDiagnosticsIDMap(CustomDiagnosticTotal), Visitor(*this) {
auto &DE = Instance.getDiagnostics();

CustomDiagnosticsIDMap[CustomDiagnosticVectorsMoreThan4Elements] =
Expand All @@ -96,6 +123,9 @@ struct ExtraValidationConsumer final : public ASTConsumer {
return false;
}
}

// Check for unsupported vector types.
Visitor.TraverseDecl(FD);
}
}
}
Expand Down

0 comments on commit 099ce2a

Please sign in to comment.