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

[libc] abs is a const function #79650

Closed
wants to merge 1 commit into from
Closed

Conversation

AtariDreams
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the libc label Jan 26, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 26, 2024

@llvm/pr-subscribers-libc

Author: AtariDreams (AtariDreams)

Changes

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

1 Files Affected:

  • (modified) libc/src/stdlib/abs.h (+1-1)
diff --git a/libc/src/stdlib/abs.h b/libc/src/stdlib/abs.h
index 19cef1446bd36df..ccfdccf2024a9e7 100644
--- a/libc/src/stdlib/abs.h
+++ b/libc/src/stdlib/abs.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-int abs(int n);
+int __attribute__((__const__)) abs(int n);
 
 } // namespace LIBC_NAMESPACE
 

@jhuber6
Copy link
Contributor

jhuber6 commented Jan 26, 2024

@michaelrj-google Do we have a formalized way to specify attributes? My gut says it should go in libc/spec/stdc.td but I remember hearing there was some desire to move away from tablegen?

@AtariDreams
Copy link
Contributor Author

@michaelrj-google Do we have a formalized way to specify attributes? My gut says it should go in libc/spec/stdc.td but I remember hearing there was some desire to move away from tablegen?

I have no idea how to do it in tablegen

@jhuber6
Copy link
Contributor

jhuber6 commented Jan 26, 2024

As it stands, this won't be exported. The header modified is simply the internal header. The installed ones go through a tool called lib-hdrgen which uses LLVM TableGen to spit the definitions out into where %%public_api() is.

libc/src/stdlib/abs.h Outdated Show resolved Hide resolved
@jhuber6
Copy link
Contributor

jhuber6 commented Jan 26, 2024

I have no idea how to do it in tablegen

I was asking Michael, because I recall that this is an existing issue that the infrastructure hasn't solved yet. I had problems earlier where it conflicted with a lot of GNU definitions that expect things like pure or similar.

@SchrodingerZhu
Copy link
Contributor

SchrodingerZhu commented Jan 26, 2024

We have internal versions of math kernels inside LIBC_NAMESPACE. I think it is legitimate to add additional attributes to these internal versions of these functions if found helpful (improving codegen of other internal functions). Adding non-standard attributes to the exposed version as specified in spec.td sometimes will lead to problems.

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

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

This approval is to dismiss previous "Request changes". I don't know how to dismiss a "Request changes" without approving the PR.

@AtariDreams AtariDreams closed this Feb 4, 2024
@nickdesaulniers
Copy link
Member

Isn't #79891 trying to add generalized support for attributes?

@jhuber6
Copy link
Contributor

jhuber6 commented Feb 5, 2024

Isn't #79891 trying to add generalized support for attributes?

I think the attributes on the installed headers and the internal headers are separate.

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.

None yet

5 participants