Skip to content

Conversation

@lntue
Copy link
Contributor

@lntue lntue commented Nov 14, 2025

By only defining it if LIBC_ASSERT macro is not defined.

Fixes #162392

@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2025

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

By only defining it if LIBC_ASSERT macro is not defined.

Fixes #162392


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

1 Files Affected:

  • (modified) libc/src/__support/libc_assert.h (+2)
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index ada1795ccb80a..6e0b5bd3d68b4 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -14,9 +14,11 @@
 // The build is configured to just use the public <assert.h> API
 // for libc's internal assertions.
 
+#ifndef LIBC_ASSERT
 #include <assert.h>
 
 #define LIBC_ASSERT(COND) assert(COND)
+#endif // LIBC_ASSERT
 
 #else // Not LIBC_COPT_USE_C_ASSERT
 

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

Just curious, what is LIBC_COPT_USE_C_ASSERT?

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

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

LGTM

@michaelrj-google
Copy link
Contributor

Just curious, what is LIBC_COPT_USE_C_ASSERT?

It selects if we want to use the public C assert API or our own internal API for assertions.

@lntue
Copy link
Contributor Author

lntue commented Nov 14, 2025

Just curious, what is LIBC_COPT_USE_C_ASSERT?

It is to skip the internal implementation of assertion in full build mode, mostly to be used in GPU offload or embedded systems.

@lntue lntue merged commit cfce4a6 into llvm:main Nov 14, 2025
22 checks passed
@lntue lntue deleted the assert branch November 14, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLVM libc used its own definition of LIBC_ASSERT in libc++

4 participants