Skip to content

[compiler-rt] Define __STDC_FORMAT_MACROS to ensure PRId64 is available #102980

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 1 commit into from
Aug 13, 2024

Conversation

giordano
Copy link
Contributor

@giordano giordano commented Aug 12, 2024

In JuliaPackaging/Yggdrasil#9246 (comment) we ran into

[20:54:03] [ 65%] Building CXX object lib/scudo/standalone/CMakeFiles/RTScudoStandalone.x86_64.dir/timing.cpp.o
[20:54:03] cd /workspace/srcdir/compiler-rt-17.0.6.src/build/lib/scudo/standalone && /opt/bin/x86_64-linux-gnu-libgfortran5-cxx11/x86_64-linux-gnu-g++ --sysroot=/opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/  -I/workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/../.. -I/workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/include -Wall -Wno-unused-parameter -O3 -DNDEBUG -m64 -Werror=conversion -Wall -Wextra -pedantic -g -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-pedantic -fno-lto -O3 -fno-omit-frame-pointer -DGWP_ASAN_HOOKS -std=c++17 -MD -MT lib/scudo/standalone/CMakeFiles/RTScudoStandalone.x86_64.dir/timing.cpp.o -MF CMakeFiles/RTScudoStandalone.x86_64.dir/timing.cpp.o.d -o CMakeFiles/RTScudoStandalone.x86_64.dir/timing.cpp.o -c /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.cpp
[...]
[20:54:03] In file included from /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.cpp:9:
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h: In member function ‘void scudo::TimingManager::printImpl(scudo::ScopedString&, scudo::u32, scudo::u32)’:
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:182:21: error: expected ‘)’ before ‘PRId64’
[20:54:03]      Str.append("%14" PRId64 ".%" PRId64 "(ns) %-11s", Integral, Fraction, " ");
[20:54:03]                ~     ^~~~~~~
[20:54:03]                      )
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:182:16: warning: conversion lacks type at end of format [-Wformat=]
[20:54:03]      Str.append("%14" PRId64 ".%" PRId64 "(ns) %-11s", Integral, Fraction, " ");
[20:54:03]                 ^~~~~
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:182:16: warning: too many arguments for format [-Wformat-extra-args]
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:186:23: error: expected ‘)’ before ‘PRId64’
[20:54:03]      Str.append("%s (%" PRId64 ")\n", Timers[HandleId].Name, Occurrence);
[20:54:03]                ~       ^~~~~~~
[20:54:03]                        )
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:186:16: warning: spurious trailing ‘%’ in format [-Wformat=]
[20:54:03]      Str.append("%s (%" PRId64 ")\n", Timers[HandleId].Name, Occurrence);
[20:54:03]                 ^~~~~~~

when compiling compiler-rt with GCC 8. This was resolved by defining __STDC_FORMAT_MACROS.

Copy link

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
Copy link
Member

llvmbot commented Aug 12, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Mosè Giordano (giordano)

Changes

In JuliaPackaging/Yggdrasil#9246 (comment) we ran into

[20:54:03] In file included from /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.cpp:9:
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h: In member function ‘void scudo::TimingManager::printImpl(scudo::ScopedString&, scudo::u32, scudo::u32)’:
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:182:21: error: expected ‘)’ before ‘PRId64’
[20:54:03]      Str.append("%14" PRId64 ".%" PRId64 "(ns) %-11s", Integral, Fraction, " ");
[20:54:03]                ~     ^~~~~~~
[20:54:03]                      )
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:182:16: warning: conversion lacks type at end of format [-Wformat=]
[20:54:03]      Str.append("%14" PRId64 ".%" PRId64 "(ns) %-11s", Integral, Fraction, " ");
[20:54:03]                 ^~~~~
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:182:16: warning: too many arguments for format [-Wformat-extra-args]
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:186:23: error: expected ‘)’ before ‘PRId64’
[20:54:03]      Str.append("%s (%" PRId64 ")\n", Timers[HandleId].Name, Occurrence);
[20:54:03]                ~       ^~~~~~~
[20:54:03]                        )
[20:54:03] /workspace/srcdir/compiler-rt-17.0.6.src/lib/scudo/standalone/timing.h:186:16: warning: spurious trailing ‘%’ in format [-Wformat=]
[20:54:03]      Str.append("%s (%" PRId64 ")\n", Timers[HandleId].Name, Occurrence);
[20:54:03]                 ^~~~~~~

when compiling compiler-rt with GCC 8. This was resolved by defining __STDC_FORMAT_MACROS.


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

1 Files Affected:

  • (modified) compiler-rt/lib/scudo/standalone/timing.h (+2)
diff --git a/compiler-rt/lib/scudo/standalone/timing.h b/compiler-rt/lib/scudo/standalone/timing.h
index de741edbff5fff..e125d6bdf558e7 100644
--- a/compiler-rt/lib/scudo/standalone/timing.h
+++ b/compiler-rt/lib/scudo/standalone/timing.h
@@ -14,6 +14,8 @@
 #include "string_utils.h"
 #include "thread_annotations.h"
 
+// Ensure PRId64 macro is available 
+#define __STDC_FORMAT_MACROS 1
 #include <inttypes.h>
 #include <string.h>
 

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

Copy link

github-actions bot commented Aug 12, 2024

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

@giordano
Copy link
Contributor Author

I should have addressed all issues mentioned above.

To further motivate this PR, note that __STDC_FORMAT_MACROS is already defined in other files of compiler-rt for the same reason:

// RHEL creates the PRIu64 format macro (for printing uint64_t's) only when this
// macro is defined before including <inttypes.h>.
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS 1
#endif

@fmayer fmayer requested a review from ChiaHungDuan August 12, 2024 22:33
@fmayer
Copy link
Contributor

fmayer commented Aug 12, 2024

Thanks for the PR.

Looks good to me, but adding someone from scudo to take a look.

Copy link
Contributor

@cferris1000 cferris1000 left a comment

Choose a reason for hiding this comment

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

LGTM.

@fmayer
Copy link
Contributor

fmayer commented Aug 13, 2024

I think your email address is still the GitHub alias @giordano

See #102980 (comment)

@giordano
Copy link
Contributor Author

I think your email address is still the GitHub alias @giordano

No, it's not: https://github.com/llvm/llvm-project/commit/098147142661a6b3ce058f92a2a0a958cdcef15c.patch.

See #102980 (comment)

I don't think that check ran again after I pushed, since it's triggered only on pull-request opening:

on:
pull_request:
types:
- opened

@fmayer
Copy link
Contributor

fmayer commented Aug 13, 2024

Hmm I can merge it manually. The GitHub UI still shows "This commit will be authored by [email protected]"

@giordano
Copy link
Contributor Author

Can you please try again now?

@fmayer fmayer merged commit 248e885 into llvm:main Aug 13, 2024
7 checks passed
@fmayer
Copy link
Contributor

fmayer commented Aug 13, 2024

Can you please try again now?

That worked, thanks

Copy link

@giordano 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 receive 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!

@giordano giordano deleted the patch-1 branch August 13, 2024 16:22
Zentrik added a commit to Zentrik/llvm-project that referenced this pull request Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants