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

[llvm][cmake] Performing expensive checks requires enabling assert. #80821

Merged
merged 5 commits into from
Feb 23, 2024

Conversation

huaatian
Copy link
Contributor

@huaatian huaatian commented Feb 6, 2024

LLVM will intercept errors using assert() when LLVM_ENABLE_EXPENSIVE_CHECKS is ON. So an explicit check is added.

Copy link

github-actions bot commented Feb 6, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the llvm:ir label Feb 6, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 6, 2024

@llvm/pr-subscribers-llvm-ir

Author: None (huaatian)

Changes

Protection needs to be added to these two unit tests to prevent execution when NDEBUG is defined.


Full diff: https://github.com/llvm/llvm-project/pull/80821.diff

2 Files Affected:

  • (modified) llvm/unittests/IR/BasicBlockTest.cpp (+2)
  • (modified) llvm/unittests/IR/FunctionTest.cpp (+2)
diff --git a/llvm/unittests/IR/BasicBlockTest.cpp b/llvm/unittests/IR/BasicBlockTest.cpp
index 3756f227143a50..79bf72bf32f914 100644
--- a/llvm/unittests/IR/BasicBlockTest.cpp
+++ b/llvm/unittests/IR/BasicBlockTest.cpp
@@ -472,6 +472,7 @@ TEST(BasicBlockTest, SpliceInstrRange) {
 }
 
 #ifdef EXPENSIVE_CHECKS
+#ifndef NDEBUG
 TEST(BasicBlockTest, SpliceEndBeforeBegin) {
   LLVMContext Ctx;
   std::unique_ptr<Module> M = parseIR(Ctx, R"(
@@ -503,6 +504,7 @@ TEST(BasicBlockTest, SpliceEndBeforeBegin) {
                             FromI1->getIterator()),
                "FromBeginIt not before FromEndIt!");
 }
+#endif //NDEBUG
 #endif //EXPENSIVE_CHECKS
 
 TEST(BasicBlockTest, EraseRange) {
diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp
index 8e77dfbb9dbd99..cb364cf3028871 100644
--- a/llvm/unittests/IR/FunctionTest.cpp
+++ b/llvm/unittests/IR/FunctionTest.cpp
@@ -410,6 +410,7 @@ TEST(FunctionTest, SpliceBBRange) {
 }
 
 #ifdef EXPENSIVE_CHECKS
+#ifndef NDEBUG
 TEST(FunctionTest, SpliceEndBeforeBegin) {
   LLVMContext Ctx;
   std::unique_ptr<Module> M = parseIR(Ctx, R"(
@@ -442,6 +443,7 @@ TEST(FunctionTest, SpliceEndBeforeBegin) {
                            FromBB1->getIterator()),
                "FromBeginIt not before FromEndIt!");
 }
+#endif //NDEBUG
 #endif //EXPENSIVE_CHECKS
 
 TEST(FunctionTest, EraseBBs) {

Copy link

github-actions bot commented Feb 6, 2024

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

@huaatian
Copy link
Contributor Author

@vporpo

@huaatian
Copy link
Contributor Author

@aeubanks, this issue was discovered in our downstream project. Could you please help review it? Thank you.

@aeubanks
Copy link
Contributor

it doesn't really make sense to run expensive checks without asserts, I wouldn't consider that configuration supported

@huaatian
Copy link
Contributor Author

it doesn't really make sense to run expensive checks without asserts, I wouldn't consider that configuration supported

Thank you for reviewing the code. Indeed, in most cases, when EXPENSIVE_CHECKS is enabled, !NDEBUG is also set. However, I understand that there is no explicit binding between these two situations. For example, in a few cases, I would like to use the checks that report errors with errs(), rather than using assert(). This can be considered as a tolerable medium complexity check. Is this understanding correct? I would appreciate your opinion.

@huaatian
Copy link
Contributor Author

And also, when the user enables EXPENSIVE_CHECKS and NDEBUG, there is no prompt that such settings are wrong, but these two unit tests will fail. I think this is an issue.

@aeubanks
Copy link
Contributor

For example, in a few cases, I would like to use the checks that report errors with errs(), rather than using assert().

I don't understand this sentence, can you clarify?

And also, when the user enables EXPENSIVE_CHECKS and NDEBUG, there is no prompt that such settings are wrong, but these two unit tests will fail. I think this is an issue.

That's fair, it would be good to have a check for this either in CMake or in some header. I would prefer this option.

@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Feb 21, 2024
@huaatian
Copy link
Contributor Author

That's fair, it would be good to have a check for this either in CMake or in some header. I would prefer this option.

So, I added a check in CMake, would that be appropriate?

@aeubanks
Copy link
Contributor

please update the commit description and title

thanks for doing this!

When LLVM_ENABLE_EXPENSIVE_CHECKS is ON, LLVM will intercept errors
using assert(). So, an explicit check is added.
@huaatian huaatian changed the title [llvm][unittests] add NDEBUG for some unittests [llvm][cmake] Performing expensive checks requires enabling assert. Feb 23, 2024
@lcvon007 lcvon007 merged commit 5ccf546 into llvm:main Feb 23, 2024
4 checks passed
Copy link

@huaatian Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular llvm:ir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants