Skip to content

3c no longer crashes when encountering intrinsics #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/3C/ConstraintResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class ConstraintResolver {
CVarSet getBaseVarPVConstraint(DeclRefExpr *Decl);

PVConstraint *getRewritablePVConstraint(Expr *E);


bool isNonPtrType(QualType &TE);

};

#endif // LLVM_CLANG_3C_CONSTRAINTRESOLVER_H
12 changes: 8 additions & 4 deletions clang/lib/3C/ConstraintResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) {
E = E->IgnoreParens();

// Non-pointer (int, char, etc.) types have a special base PVConstraint.
if (TypE->isRecordType() || TypE->isArithmeticType()) {
if (isNonPtrType(TypE)) {
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
// If we have a DeclRef, the PVC can get a meaningful name
return pairWithEmptyBkey(getBaseVarPVConstraint(DRE));
Expand Down Expand Up @@ -690,11 +690,15 @@ void ConstraintResolver::constrainLocalAssign(Stmt *TSt, DeclaratorDecl *D,
}
}

bool ConstraintResolver::isNonPtrType(QualType &TE) {
return TE->isRecordType() || TE->isArithmeticType() || TE->isVectorType();
}

CVarSet ConstraintResolver::pvConstraintFromType(QualType TypE) {
assert("Pointer type CVs should be obtained through getExprConstraintVars." &&
!TypE->isPointerType());
CVarSet Ret;
if (TypE->isRecordType() || TypE->isArithmeticType())
if (isNonPtrType(TypE))
Ret.insert(PVConstraint::getNonPtrPVConstraint(Info.getConstraints()));
else
llvm::errs() << "Warning: Returning non-base, non-wild type";
Expand All @@ -705,8 +709,8 @@ CVarSet ConstraintResolver::getBaseVarPVConstraint(DeclRefExpr *Decl) {
if (Info.hasPersistentConstraints(Decl, Context))
return Info.getPersistentConstraintsSet(Decl, Context);

assert(Decl->getType()->isRecordType() ||
Decl->getType()->isArithmeticType());
auto T = Decl->getType();
assert(isNonPtrType(T));

CVarSet Ret;
auto DN = Decl->getDecl()->getName();
Expand Down
12 changes: 12 additions & 0 deletions clang/test/3C/simd1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Simple SIMD program that involves no pointers, we just want this to not crash
// RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -alltypes -addcr %s

typedef int v4si __attribute__ ((vector_size(16)));

void main(void) {
v4si x = {1,2,3,4};
v4si y = {1,2,3,4};
v4si z = x + y;

}
12 changes: 12 additions & 0 deletions clang/test/3C/simd2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Simple SIMD program that derefs and involves no pointers, we just want this to not crash,
// RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -alltypes -addcr %s
typedef int v4si __attribute__ ((vector_size(16)));

int main(void) {
v4si x = {1,2,3,4};
v4si y = {1,2,3,4};
v4si z = x + y;

return (z[0] + z[1] + z[3] + z[4]);
}
7 changes: 7 additions & 0 deletions clang/test/3C/simd3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Original minimized failing simd program
// RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -alltypes -addcr %s

__attribute__((__vector_size__(2 * sizeof(long)))) int a() {
return (__attribute__((__vector_size__(2 * sizeof(long))))int){};
}