Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvmgcc] Variable length array indexing miscompiled #670

Closed
lattner opened this issue Mar 17, 2004 · 2 comments
Closed

[llvmgcc] Variable length array indexing miscompiled #670

lattner opened this issue Mar 17, 2004 · 2 comments

Comments

@lattner
Copy link
Collaborator

lattner commented Mar 17, 2004

Bugzilla Link 298
Resolution FIXED
Resolved on Feb 22, 2010 12:45
Version 1.0
OS All

Extended Description

It looks like we are miscompiling indexes through C99 VLA's in some cases. File
this into the "wow, I didn't know you could do that" catagory. :)

Testcase:


int foo(int len, char arr[][len], int X) {
return arr[X][0];
}

The correct addressing arithmetic to generate is "arr + X*len", which we don't
do in this case.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Apr 23, 2004

Here's another horrible testcase with the same issue:

int sub1 (int i, int j) {
typedef struct {
int c[i+2];
}c;
int x[10], y[10];

if (j == 2) {
memcpy (x, y, 10 * sizeof (int));
return sizeof (c);
} else
return sizeof (c) * 3;
}

int main() {
typedef struct {
int c[22];
}c;
if (sub1 (20, 3) != sizeof (c)*3)
abort ();
return 0;
}

@lattner
Copy link
Collaborator Author

lattner commented May 7, 2004

This patch:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040503/014167.html

Fixes this testcase (test/Regression/CFrontend/2004-05-07-VarArrays.c):

int foo(int len, char arr[][len], int X) {
return arr[X][0];
}

The second testcase attached to this bug is actually a bug in the non-LLVM
specific portion of GCC, so it will magically be fixed when new bits are merged in.

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 1, 2021
pysuxing pushed a commit to pysuxing/llvm-project that referenced this issue Jul 17, 2024
LLVM lowering for the following operations is introduced in llvm#616 and
llvm#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
keryell pushed a commit to keryell/llvm-project that referenced this issue Oct 19, 2024
LLVM lowering for the following operations is introduced in llvm#616 and
llvm#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant