-
Notifications
You must be signed in to change notification settings - Fork 110
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
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`.
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`.
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`.
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`.
#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`.
__sync_fetch_and_add
currently doesn't support unsigned integers.The following code snippet, for example, raises an error:
The error can be traced down to this line
auto intType = builder.getSIntNTy(cgf.getContext().getTypeSize(typ));
fromclang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
.