Skip to content

Commit

Permalink
[ClavaWeaver] Adds test for issue #168
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobispo committed Nov 11, 2024
1 parent 4ea929f commit f232326
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ClavaWeaver/resources/clava/test/issues/Issue168.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Query from "@specs-feup/lara/api/weaver/Query.js";

//laraImport("weaver.Query");
laraImport("Joinpoints");
//import {FunctionJp, Statement} from "@specs-feup/clava/api/Joinpoints.js";
laraImport("clava.code.StatementDecomposer");
laraImport("clava.opt.NormalizeToSubset");

for (const fun of Query.search(FunctionJp, {"isImplementation": true})) {
const body = fun.body;
NormalizeToSubset(body, {simplifyLoops: {forToWhile: false}});
}

const decomp = new StatementDecomposer();
for (var stmt of Query.search(Statement, {isInsideHeader: false})) {
decomp.decomposeAndReplace(stmt);
}

println(Query.root().code);
44 changes: 44 additions & 0 deletions ClavaWeaver/resources/clava/test/issues/c/results/Issue168.mjs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**** File 'issue_168.c' ****/
#include <stdio.h>
float buzz(int *A, double *B, char C[]) {
for(int i = 0; i < 100; i++) {
C[i] = 0;
}
int *X;
for(int i = 0; i < 100; i++) {
int decomp_0;
decomp_0 = C[i] + 1;
C[i] = decomp_0;
for(int j = 0; j < 100; j++) {
int decomp_0;
int decomp_1;
decomp_1 = C[i] > 0;
decomp_0 = decomp_1;
if(decomp_0) return 0.3;
int decomp_2;
decomp_2 = C[j] + 2;
C[j] = decomp_2;
for(int k = 0; k < 100; k++) {
int decomp_3;
decomp_3 = C[k] + 3;
C[k] = decomp_3;
int decomp_1;
int decomp_4;
decomp_4 = C[k] > 0;
decomp_1 = decomp_4;
if(decomp_1) {

return 0.4;
}
for(int l = 0; l < 100; l++) {
int decomp_5;
decomp_5 = C[l] + 4;
C[l] = decomp_5;
}
}
}
}

return 0.6;
}
/**** End File ****/
34 changes: 34 additions & 0 deletions ClavaWeaver/resources/clava/test/issues/c/src/issue_168.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>

float buzz(int *A, double *B, char C[])
{
for (int i = 0; i < 100; i++)
{
C[i] = 0;
}
int *X;
for (int i = 0; i < 100; i++)
{
C[i] = C[i] + 1;
for (int j = 0; j < 100; j++)
{
if (C[i] > 0)
return 0.3;
C[j] = C[j] + 2;
for (int k = 0; k < 100; k++)
{
C[k] = C[k] + 3;
if (C[k] > 0)
{

return 0.4;
}
for (int l = 0; l < 100; l++)
{
C[l] = C[l] + 4;
}
}
}
}
return 0.6;
}
48 changes: 48 additions & 0 deletions ClavaWeaver/test/pt/up/fe/specs/cxxweaver/tests/CIssueTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2016 SPeCS.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. under the License.
*/

package pt.up.fe.specs.cxxweaver.tests;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import pt.up.fe.specs.clava.language.Standard;
import pt.up.fe.specs.cxxweaver.ClavaWeaverTester;
import pt.up.fe.specs.util.SpecsSystem;

public class CIssueTest {

@BeforeClass
public static void setupOnce() {
SpecsSystem.programStandardInit();
ClavaWeaverTester.clean();
}

@After
public void tearDown() {
ClavaWeaverTester.clean();
}

private static ClavaWeaverTester newTester() {
return new ClavaWeaverTester("clava/test/issues/", Standard.C99)
.setResultPackage("c/results")
.setSrcPackage("c/src");
}


@Test
public void testIssue168() {
newTester().test("Issue168.mjs", "issue_168.c");
}

}

0 comments on commit f232326

Please sign in to comment.