Skip to content

Commit 0b2ee87

Browse files
author
Aaron Eline
authored
3c no longer crashes when encountering intrinsics (#633)
* Test case for SIMD * Seperated concerns in test cases * 3c no longer crashes in presence of intrinsics * Fixing minor comments from john
1 parent f10df90 commit 0b2ee87

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

clang/include/clang/3C/ConstraintResolver.h

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class ConstraintResolver {
7878
CVarSet getBaseVarPVConstraint(DeclRefExpr *Decl);
7979

8080
PVConstraint *getRewritablePVConstraint(Expr *E);
81+
82+
83+
bool isNonPtrType(QualType &TE);
84+
8185
};
8286

8387
#endif // LLVM_CLANG_3C_CONSTRAINTRESOLVER_H

clang/lib/3C/ConstraintResolver.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) {
164164
E = E->IgnoreParens();
165165

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

693+
bool ConstraintResolver::isNonPtrType(QualType &TE) {
694+
return TE->isRecordType() || TE->isArithmeticType() || TE->isVectorType();
695+
}
696+
693697
CVarSet ConstraintResolver::pvConstraintFromType(QualType TypE) {
694698
assert("Pointer type CVs should be obtained through getExprConstraintVars." &&
695699
!TypE->isPointerType());
696700
CVarSet Ret;
697-
if (TypE->isRecordType() || TypE->isArithmeticType())
701+
if (isNonPtrType(TypE))
698702
Ret.insert(PVConstraint::getNonPtrPVConstraint(Info.getConstraints()));
699703
else
700704
llvm::errs() << "Warning: Returning non-base, non-wild type";
@@ -705,8 +709,8 @@ CVarSet ConstraintResolver::getBaseVarPVConstraint(DeclRefExpr *Decl) {
705709
if (Info.hasPersistentConstraints(Decl, Context))
706710
return Info.getPersistentConstraintsSet(Decl, Context);
707711

708-
assert(Decl->getType()->isRecordType() ||
709-
Decl->getType()->isArithmeticType());
712+
auto T = Decl->getType();
713+
assert(isNonPtrType(T));
710714

711715
CVarSet Ret;
712716
auto DN = Decl->getDecl()->getName();

clang/test/3C/simd1.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Simple SIMD program that involves no pointers, we just want this to not crash
2+
// RUN: rm -rf %t*
3+
// RUN: 3c -base-dir=%S -alltypes -addcr %s
4+
5+
typedef int v4si __attribute__ ((vector_size(16)));
6+
7+
void main(void) {
8+
v4si x = {1,2,3,4};
9+
v4si y = {1,2,3,4};
10+
v4si z = x + y;
11+
12+
}

clang/test/3C/simd2.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Simple SIMD program that derefs and involves no pointers, we just want this to not crash,
2+
// RUN: rm -rf %t*
3+
// RUN: 3c -base-dir=%S -alltypes -addcr %s
4+
typedef int v4si __attribute__ ((vector_size(16)));
5+
6+
int main(void) {
7+
v4si x = {1,2,3,4};
8+
v4si y = {1,2,3,4};
9+
v4si z = x + y;
10+
11+
return (z[0] + z[1] + z[3] + z[4]);
12+
}

clang/test/3C/simd3.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Original minimized failing simd program
2+
// RUN: rm -rf %t*
3+
// RUN: 3c -base-dir=%S -alltypes -addcr %s
4+
5+
__attribute__((__vector_size__(2 * sizeof(long)))) int a() {
6+
return (__attribute__((__vector_size__(2 * sizeof(long))))int){};
7+
}

0 commit comments

Comments
 (0)