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

[CIR][CirGen][Bugfix] Fixes __sync_fetch_and_add for unsigned integers #799

Merged
merged 4 commits into from
Aug 23, 2024
Merged

[CIR][CirGen][Bugfix] Fixes __sync_fetch_and_add for unsigned integers #799

merged 4 commits into from
Aug 23, 2024

Conversation

bruteforceboy
Copy link
Contributor

__sync_fetch_and_add currently doesn't support unsigned integers.

The following code snippet, for example, raises an error:

#include <stdint.h>

void foo(uint64_t x) {
  __sync_fetch_and_add(&x, 1);
}

The error can be traced down to this line auto intType = builder.getSIntNTy(cgf.getContext().getTypeSize(typ)); from clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, minor changes and good to go

#include <stdint.h>

void foo(int64_t x) {
__sync_fetch_and_add(&x, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the new testfiles, incorporate this with other __sync_fetch_and_add testing in clang/test/CIR/CodeGen/atomic.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

if (expr->getArg(0)->getType()->getPointeeType()->isUnsignedIntegerType())
intType = builder.getUIntNTy(cgf.getContext().getTypeSize(typ));
else
intType = builder.getSIntNTy(cgf.getContext().getTypeSize(typ));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also do a oneliner here:

mlir::cir::IntType intType = expr->getArg(0)->getType()->getPointeeType()->isUnsignedIntegerType() ? builder.getUIntNTy(cgf.getContext().getTypeSize(typ)) : builder.getSIntNTy(cgf.getContext().getTypeSize(typ));

clang-format will help out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@bcardosolopes bcardosolopes merged commit 2360bc9 into llvm:main Aug 23, 2024
6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
llvm#799)

`__sync_fetch_and_add` currently doesn't support unsigned integers. 

The following code snippet, for example, raises an error:  
```
#include <stdint.h>

void foo(uint64_t x) {
  __sync_fetch_and_add(&x, 1);
}
```
The error can be traced down to this line `auto intType =
builder.getSIntNTy(cgf.getContext().getTypeSize(typ));` from
`clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp`.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
llvm#799)

`__sync_fetch_and_add` currently doesn't support unsigned integers. 

The following code snippet, for example, raises an error:  
```
#include <stdint.h>

void foo(uint64_t x) {
  __sync_fetch_and_add(&x, 1);
}
```
The error can be traced down to this line `auto intType =
builder.getSIntNTy(cgf.getContext().getTypeSize(typ));` from
`clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp`.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
llvm#799)

`__sync_fetch_and_add` currently doesn't support unsigned integers. 

The following code snippet, for example, raises an error:  
```
#include <stdint.h>

void foo(uint64_t x) {
  __sync_fetch_and_add(&x, 1);
}
```
The error can be traced down to this line `auto intType =
builder.getSIntNTy(cgf.getContext().getTypeSize(typ));` from
`clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp`.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
llvm#799)

`__sync_fetch_and_add` currently doesn't support unsigned integers. 

The following code snippet, for example, raises an error:  
```
#include <stdint.h>

void foo(uint64_t x) {
  __sync_fetch_and_add(&x, 1);
}
```
The error can be traced down to this line `auto intType =
builder.getSIntNTy(cgf.getContext().getTypeSize(typ));` from
`clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp`.
lanza pushed a commit that referenced this pull request Nov 5, 2024
#799)

`__sync_fetch_and_add` currently doesn't support unsigned integers. 

The following code snippet, for example, raises an error:  
```
#include <stdint.h>

void foo(uint64_t x) {
  __sync_fetch_and_add(&x, 1);
}
```
The error can be traced down to this line `auto intType =
builder.getSIntNTy(cgf.getContext().getTypeSize(typ));` from
`clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp`.
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

Successfully merging this pull request may close these issues.

2 participants