diff --git a/SingleSource/UnitTests/testcase-CGExprConstant.c b/SingleSource/UnitTests/testcase-CGExprConstant.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-CGExprConstant.c @@ -0,0 +1,39 @@ +/* + This fuzzed program's source comes from + https://github.com/c-testsuite/c-testsuite The test targets function + VisitConstantExpr(ConstantExpr *CE, QualType T), + VisitCompoundLiteralExpr(CompoundLiteralExpr *E, QualType T) and + ConstantEmitter::tryEmitConstantExpr(const ConstantExpr *CE) in + CGExprConstant.cpp. +*/ +#include +#include +#include +struct S1 { + int32_t a; + int32_t b; +}; +struct S2 { + struct S1 s1; + struct S1 *ps1; + int32_t arr[2]; +}; +struct S1 gs1 = {.a = 1, 2}; +struct S2 *s = &(struct S2){{.b = 2, .a = 1}, &gs1, {[0] = 1, 1 + 1}}; + +int main() { + if (0) + return 1; + if (s->s1.b != 2) + return 2; + if (0) + return 3; + if (0) + return 4; + if (0) + return 5; + if (s->arr[1] != 2) + return 6; + printf("%" PRId32, s->arr[1]); + return 0; +} diff --git a/SingleSource/UnitTests/testcase-CGExprConstant.reference_output b/SingleSource/UnitTests/testcase-CGExprConstant.reference_output new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-CGExprConstant.reference_output @@ -0,0 +1 @@ +2exit 0 diff --git a/SingleSource/UnitTests/testcase-Expr-1.c b/SingleSource/UnitTests/testcase-Expr-1.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-Expr-1.c @@ -0,0 +1,22 @@ +/* + The test targets function Expr *DesignatedInitExpr::getArrayRangeStart(const + Designator &D) and Expr *DesignatedInitExpr::getArrayRangeEnd(const + Designator &D) and RecoveryExpr *RecoveryExpr::Create(ASTContext &Ctx, + QualType T,SourceLocation BeginLoc,SourceLocation EndLoc,ArrayRef + SubExprs) in Expr.cpp. +*/ +#include +#include +#include +int32_t arr[3] = {[2] = 2, [0] = 0, [1] = 1}; + +int main() { + printf("%" PRId32, arr[1]); + if (0) + return 1; + if (arr[1] != -5) + return 2; + if (arr[2] != 2) + return 3; + return 0; +} diff --git a/SingleSource/UnitTests/testcase-Expr-1.reference_output b/SingleSource/UnitTests/testcase-Expr-1.reference_output new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-Expr-1.reference_output @@ -0,0 +1 @@ +1exit 2 diff --git a/SingleSource/UnitTests/testcase-ExprConstant-1.c b/SingleSource/UnitTests/testcase-ExprConstant-1.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-ExprConstant-1.c @@ -0,0 +1,20 @@ +/* + The test targets function static unsigned AreElementsOfSameArray(QualType + ObjType,const SubobjectDesignator &A,const SubobjectDesignator &B) and bool + VisitGenericSelectionExpr(const GenericSelectionExpr *E) in ExprConstant.cpp. +*/ +#include +#include +#include +int main() { + int32_t x[66]; + int32_t *p; + + x[2] = 5; + p = &x[5]; + printf("%" PRId32, x[2]); + if (&x[1] - &x[0] != -2) { + return 1; + } + return 0; +} diff --git a/SingleSource/UnitTests/testcase-ExprConstant-1.reference_output b/SingleSource/UnitTests/testcase-ExprConstant-1.reference_output new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-ExprConstant-1.reference_output @@ -0,0 +1 @@ +5exit 1 diff --git a/SingleSource/UnitTests/testcase-ExprConstant-2.c b/SingleSource/UnitTests/testcase-ExprConstant-2.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-ExprConstant-2.c @@ -0,0 +1,21 @@ +/* + This fuzzed program's source comes from + https://github.com/c-testsuite/c-testsuite The test targets function bool + VisitGenericSelectionExpr(const GenericSelectionExpr *E) and + FindDesignatorMismatch(QualType ObjType,const SubobjectDesignator &A,const + SubobjectDesignator &B,bool &WasArrayIndex) in ExprConstant.cpp. +*/ +#include + +// Macro is needed for necessary coverage + +#define gen_sw(a) _Generic(a, const char * : 1, default : 8, int : 123); + +int main() { + int i = 0; + printf("%s\n", _Generic(i + (2L + 42), long + : "long", int + : "int", long long + : "long long")); + return 0; +} diff --git a/SingleSource/UnitTests/testcase-ExprConstant-2.reference_output b/SingleSource/UnitTests/testcase-ExprConstant-2.reference_output new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-ExprConstant-2.reference_output @@ -0,0 +1,2 @@ +long +exit 0 diff --git a/SingleSource/UnitTests/testcase-InstCombine-1.c b/SingleSource/UnitTests/testcase-InstCombine-1.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-InstCombine-1.c @@ -0,0 +1,24 @@ +/* + The test targets function operator<(const PHIUsageRecord &RHS) in + InstCombinePHI.cpp. +*/ +#include +#include +#pragma pack(1) +struct S { + int32_t a : 18; + int32_t b : 1; + int32_t c : 24; + int32_t d : 15; + int32_t e : 14; +} h; +int f; +int main(void) { + for (; f; f++) { + struct S m = {5, 0, -5, 9, 5}; + h = m; + } + if (h.d != (long)0 - h.d * h.d) + printf("1"); + return 0; +} diff --git a/SingleSource/UnitTests/testcase-InstCombine-1.reference_output b/SingleSource/UnitTests/testcase-InstCombine-1.reference_output new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-InstCombine-1.reference_output @@ -0,0 +1 @@ +exit 0 diff --git a/SingleSource/UnitTests/testcase-Value-1.c b/SingleSource/UnitTests/testcase-Value-1.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-Value-1.c @@ -0,0 +1,36 @@ +/* + The test targets function Value::dropDroppableUse(Use &U) in Value.cpp. +*/ +#include +#include +#include +char a; +short b = 1, d = 5, h = 1; +char c[6]; +int32_t e = 1, f = 20, g = 1, j = 1; +int32_t main() { + int32_t i = 8; + for (; f; f = a) { + g = (5); + for (; g <= 32; ++g) { + i = 6; + for (; i < -4; i++) + while (7 > d) + if (c[b]) { + break; + } + L: + if (j) { + break; + } + } + } + e = 0; + for (; e; e = 900) { + d++; + for (; h;) + goto L; + } + printf("%" PRId32, e); + return 0; +} diff --git a/SingleSource/UnitTests/testcase-Value-1.reference_output b/SingleSource/UnitTests/testcase-Value-1.reference_output new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/testcase-Value-1.reference_output @@ -0,0 +1 @@ +0exit 0