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] Fix for __atomic_compare_exchange weak arg #721

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

dkolsen-pgi
Copy link
Collaborator

ClangIR was failing on

__atomic_compare_exchange_n(&a, &old, 42, true, 5, 5);

The true was the problem. It would work with a literal 0 or 1, but not with a literal true or false.

The bug was in isCstWeak in CIRGenAtomic.cpp, which was only looking for an integral constant. It didn't recognize a boolean constant and was falling back on the non-constant path, which isn't implemented yet.

Rewrite isCstWeak to check for both intergral and boolean constants.

ClangIR was failing on
```
__atomic_compare_exchange_n(&a, &old, 42, true, 5, 5);
```
The `true` was the problem.  It would work with a literal `0` or `1`,
but not with a literal `true` or `false`.

The bug was in `isCstWeak` in CIRGenAtomic.cpp, which was only looking
for an integral constant.  It didn't recognize a boolean constant and
was falling back on the non-constant path, which isn't implemented yet.

Rewrite `isCstWeak` to check for both intergral and boolean constants.
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. It's just missing a testcase and should be good to be merged!

Change some, but not all of the __atomic_compare_exchange tests to use
boolean literals instead of integer literals for the "weak" argument.
This provides test coverage for a recent fix to CodeGen of the "weak"
argument.
@dkolsen-pgi
Copy link
Collaborator Author

Test case added. Some, but not all, of the existing __atomic_compare_exchange tests were changed to use boolean literals instead of integer literals. There is now coverage for both ways of specifying the "weak" argument.

@bcardosolopes bcardosolopes merged commit 58d5f0b into llvm:main Jul 9, 2024
6 checks passed
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.

None yet

2 participants