Skip to content

Commit

Permalink
Missing error when placing a single statement for-body on a new row #…
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jan 28, 2025
1 parent af2a0ff commit 70d0ad1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
9 changes: 3 additions & 6 deletions lib/std/math/math_nolibc/rempi.c3
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ fn int __rem_pio2_large(double* x, double* y, int e0, int nx, int prec)
{
/* add q[jz+1] to q[jz+k] */
f[jx + i] = (double)IPIO2[jv + i];
for (j = 0, fw = 0.0; j <= jx; j++)
fw += x[j] * f[jx + i - j];
for (j = 0, fw = 0.0; j <= jx; j++) fw += x[j] * f[jx + i - j];
q[i] = fw;
}
jz += k;
Expand Down Expand Up @@ -303,8 +302,7 @@ fn int __rem_pio2_large(double* x, double* y, int e0, int nx, int prec)
case 1:
case 2:
fw = 0.0;
for (int i = jz; i >= 0; i--)
fw += fq[i];
for (int i = jz; i >= 0; i--) fw += fq[i];
// TODO: drop excess precision here once double_t is used
fw = (double)fw;
y[0] = ih == 0 ? fw : -fw;
Expand All @@ -324,8 +322,7 @@ fn int __rem_pio2_large(double* x, double* y, int e0, int nx, int prec)
fq[i] += fq[i - 1] - fw;
fq[i - 1] = fw;
}
for (fw = 0.0, int i = jz; i >= 2; i--)
fw += fq[i];
for (fw = 0.0, int i = jz; i >= 2; i--) fw += fq[i];
if (ih == 0)
{
y[0] = fq[0];
Expand Down
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Fix issues with @jump on empty `default` or only `default` #1893 #1894
- Fixes miscompilation of nested `@jump` #1896.
- Fixed STB_WEAK errors when using consts in macros in the stdlib #1871.
- Missing error when placing a single statement for-body on a new row #1892.

### Stdlib changes
- Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter.
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/parse_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,13 @@ static inline Ast* parse_for_stmt(ParseContext *c)

// Ast range does not include the body
RANGE_EXTEND_PREV(ast);

unsigned row = c->prev_span.row;
ASSIGN_AST_OR_RET(Ast *body, parse_stmt(c), poisoned_ast);
if (body->ast_kind != AST_COMPOUND_STMT && row != body->span.row)
{
PRINT_ERROR_AT(body, "A single statement after 'for' must be placed on the same line, or be enclosed in {}.");
return poisoned_ast;
}
ast->for_stmt.body = astid(body);
return ast;
}
Expand Down
31 changes: 15 additions & 16 deletions test/test_suite/clang/2002-07.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ fn void __bb_exit_func()

extern fn int puts(char* s);

struct FunStructTest {
int test1;
char *pointer;
int[12] array;
struct FunStructTest
{
int test1;
char* pointer;
int[12] array;
}

struct SubStruct {
Expand Down Expand Up @@ -222,9 +223,7 @@ fn int funcZ(int i, int j) {
fn int sumArray(int* array, int num) {
int i @noinit;
int result = 0;
for (i = 0; i < num; ++i)
result += array[i];

for (i = 0; i < num; ++i) result += array[i];
return result;
}

Expand All @@ -235,24 +234,24 @@ fn int arrayParam(int* values) {
fn int arrayToSum() {
int[100] a @noinit;
int i;
for (i = 0; i < 100; ++i)
a[i] = i*4;
for (i = 0; i < 100; ++i) a[i] = i*4;

return a[a[0]]; //SumArray(A, 100);
}


extern fn int externFunc(long, uint*, short, char);

fn int main(int argc, char **argv) {
uint i @noinit;
puts("Hello world!\n");
fn int main(int argc, char **argv)
{
uint i @noinit;
puts("Hello world!\n");

externFunc(-1, null, (short)argc, 2);
//func(argc, argc);
externFunc(-1, null, (short)argc, 2);
//func(argc, argc);

for (i = 0; i < 10; i++) puts(argv[3]);
return 0;
for (i = 0; i < 10; i++) puts(argv[3]);
return 0;
}

fn double mathFunc(double x, double y, double z,
Expand Down
13 changes: 13 additions & 0 deletions test/test_suite/statements/for_statement_placement.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn void test(int x)
{}

fn void main()
{
for (int i = 0; i < 10; i++) test(
i
);
for (int i = 0; i < 10; i++)
test( // #error: A single statement after
i
);
}

0 comments on commit 70d0ad1

Please sign in to comment.