forked from ziglang/zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
translate-c: fix translation of "ptr += uint"
The right-hand side was incorrectly cast to a pointer, since only signed ints were being interpreted correctly as pointer arithmetic. Fixes ziglang#20285.
- Loading branch information
1 parent
08df5e3
commit d9e0f17
Showing
2 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/cases/run_translated_c/compound_assignments_with_pointer_arithmetic.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
int main() { | ||
const char *s = "forgreatjustice"; | ||
unsigned int add = 1; | ||
|
||
s += add; | ||
if (*s != 'o') return 1; | ||
|
||
s += 1UL; | ||
if (*s != 'r') return 2; | ||
|
||
const char *s2 = (s += add); | ||
if (*s2 != 'g') return 3; | ||
|
||
s2 -= add; | ||
if (*s2 != 'r') return 4; | ||
|
||
return 0; | ||
} | ||
|
||
// run-translated-c | ||
// c_frontend=clang |