Skip to content

[CIR] Implement ::verify for cir.atomic.xchg and cir.atomic.cmp_xchg #1431

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

Merged
merged 4 commits into from
Mar 18, 2025

Conversation

Icaro-Nunes
Copy link
Contributor

@Icaro-Nunes Icaro-Nunes commented Mar 1, 2025

Implements ::verify for operations cir.atomic.xchg and cir.atomic.cmp_xchg

I believe the existing regression tests don't get to the CIR level type check failure and I was not able to implement a case that does.

Most attempts of reproducing cir.atomic.xchg type check failure were along the lines of:

int a;
long long b,c;
__atomic_exchange(&a, &b, &c, memory_order_seq_cst);

And they seem to never trigger the failure on ::verify because they fail earlier in function parameter checking:

exmp.cpp:7:27: error: cannot initialize a parameter of type 'int *' with an rvalue of type 'long long *'
    7 |     __atomic_exchange(&a, &b, &c, memory_order_seq_cst);
      |                           ^~

Closes #1378 .

@Icaro-Nunes
Copy link
Contributor Author

@bcardosolopes is this the expected result? Failure at ::verify should happen only in the occasion of AST/CIRCodeGen bugs?

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, this is great! To add a testcase, see clang/test/CIR/IR/invalid.cir for inspiration

@Icaro-Nunes
Copy link
Contributor Author

Icaro-Nunes commented Mar 6, 2025

@bcardosolopes I corrected the code where requested and added the tests (clang/test/CIR/IR/invalid.cir itself seemed like the appropriate place for them)

@Icaro-Nunes Icaro-Nunes marked this pull request as ready for review March 6, 2025 08:56
@Icaro-Nunes Icaro-Nunes requested a review from lanza as a code owner March 6, 2025 08:56
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
Copy link
Member

I'll land once tests pass

Copy link

github-actions bot commented Mar 6, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@bcardosolopes
Copy link
Member

clang-format issues need fixing before landing!

@Icaro-Nunes
Copy link
Contributor Author

Done!

@Icaro-Nunes
Copy link
Contributor Author

@bcardosolopes I believe everything was fixed!

@bcardosolopes bcardosolopes merged commit 99a804b into llvm:main Mar 18, 2025
6 checks passed
lanza pushed a commit that referenced this pull request Mar 18, 2025
…1431)

Implements `::verify` for operations cir.atomic.xchg and
cir.atomic.cmp_xchg

I believe the existing regression tests don't get to the CIR level type
check failure and I was not able to implement a case that does.

Most attempts of reproducing cir.atomic.xchg type check failure were
along the lines of:
```
int a;
long long b,c;
__atomic_exchange(&a, &b, &c, memory_order_seq_cst);
```

And they seem to never trigger the failure on `::verify` because they
fail earlier in function parameter checking:
```
exmp.cpp:7:27: error: cannot initialize a parameter of type 'int *' with an rvalue of type 'long long *'
    7 |     __atomic_exchange(&a, &b, &c, memory_order_seq_cst);
      |                           ^~
```

Closes #1378 .
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.

Enhance cir.atomic.cmp_xchg and cir.atomic.xchg verifiers
2 participants