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] assert.h modifications for newhdrgen #98092

Closed
wants to merge 687 commits into from

Conversation

aaryanshukla
Copy link
Contributor

  • currently assert.h has a lot of code that does not have a position in
    our yaml files. Other files like errno.h and syscall.h have this code
    in their respective .h.def files. We want to add that feature to
    assert.h by changing assert.h.def.

@llvmbot llvmbot added the libc label Jul 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 8, 2024

@llvm/pr-subscribers-libc

Author: None (aaryanshukla)

Changes
  • currently assert.h has a lot of code that does not have a position in
    our yaml files. Other files like errno.h and syscall.h have this code
    in their respective .h.def files. We want to add that feature to
    assert.h by changing assert.h.def.

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

2 Files Affected:

  • (modified) libc/include/assert.h.def (+17)
  • (added) libc/newhdrgen/yaml/assert.yaml (+15)
diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 15077e53e2ca48..d5ae14a1cd8101 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -12,4 +12,21 @@
 // This file may be usefully included multiple times to change assert()'s
 // definition based on NDEBUG.
 
+#ifndef __cplusplus
+#undef static_assert
+#define static_assert _Static_assert
+#endif
+
+#undef assert
+#ifdef NDEBUG
+#define assert(e) (void)0
+#else
+#ifdef __cplusplus
+extern "C"
+#endif
+_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
+#define assert(e)  \
+  ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
+#endif
+
 %%public_api()
diff --git a/libc/newhdrgen/yaml/assert.yaml b/libc/newhdrgen/yaml/assert.yaml
new file mode 100644
index 00000000000000..85de6bc867b224
--- /dev/null
+++ b/libc/newhdrgen/yaml/assert.yaml
@@ -0,0 +1,15 @@
+header: assert.h
+macros: []
+types: []
+enums: []
+objects: []
+functions:
+  - name: __assert_fail 
+      - llvm_libc_ext
+    return_type: _Noreturn void
+    arguments:
+      - type: const char *
+      - type: const char *
+      - type: unsigned
+      - type: const char *
+    guard: __cplusplus
\ No newline at end of file

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.

@jhuber6 is this okay for GPUs? Right now the new headergen design doesn't have support for different macros on different platforms.

@@ -12,4 +12,21 @@
// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.

#ifndef __cplusplus
Copy link
Contributor

Choose a reason for hiding this comment

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

if you're adding this here it needs to be removed from the api.td files it's in (specifically baremetal, linux, and GPU).

Comment on lines +24 to +26
#ifdef __cplusplus
extern "C"
#endif
Copy link
Member

Choose a reason for hiding this comment

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

This file already includes __llvm-libc-common.h so you can use __BEGIN_C_DECLS and __END_C_DECLS.

@@ -12,4 +12,21 @@
// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.

#ifndef __cplusplus
#undef static_assert
#define static_assert _Static_assert
Copy link
Member

Choose a reason for hiding this comment

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

This is already defined in __llvm-libc-common.h which is included above.

- type: unsigned
- type: const char *
guard: __cplusplus

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra line here, but otherwise LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the other Yaml files all of them have a newline at the end as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are extra spaces on the newline, github will complain about it. If line is empty the line number should turn gray.


def StaticAssertMacro : MacroDef<"static_assert"> {
let Defn = [{
#ifndef __cplusplus
Copy link
Contributor

Choose a reason for hiding this comment

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

this macro also needs to be added to the .h.def

alexey-bataev and others added 12 commits July 14, 2024 18:01
Across a basic-block we might have in i32 extract from a value that only
operates on upper bits (for example a sxtw). We can replace the COPY
with a new version skipping the sxtw.
…lvm#97337)

An implied DO loop with no trips in an array constructor does not have a
well-defined character length unless its data items have a length that
is constant expression. That works, but the implementation is too
broadly applied. An array constructor with an explicit type-spec always
has a well-defined length.
…th (llvm#97353)

Make the results of the two IsInteroperableIntrinsicType() utility
routines a tri-state std::optional<bool> so that cases where the
character length is simply unknown can be distinguished from those cases
where the length is known and not acceptable. Use this distinction to
not emit a confusing warning about interoperability with C_LOC()
arguments when the length is unknown and might well be acceptable during
execution.
Support the predefined macro __TIMESTAMP__ as interpreted by GCC. It
expands to a character literal with the time of last modification of the
top-level source file in asctime(3) format, e.g. "Tue Jul 4 10:18:05
1776".
…ackages (llvm#98420)

This reduces Sphinx dependencies for building lldb man pages as lldb man
pages don't use markdown.
Section IDs are 64 bit and if a section ID was over 4GB, then the
tabular output of the "target modules dump sections" command would not
align to the column headers. Also if the section type's name was too
long, the output wouldn't algin. This patch fixes this issue.

Old output looked like:
```
(lldb) image dump sections a.out
Sections for '/tmp/a.out' (arm):
  SectID     Type             File Address                             Perm File Off.  File Size  Flags      Section Name
  ---------- ---------------- ---------------------------------------  ---- ---------- ---------- ---------- ----------------------------
  0xffffffffffffffff container        [0x0000000000001000-0x0000000000001010)  rw-  0x00000074 0x00000010 0x00000000 a.out.PT_LOAD[0]
  0x00000001 data             [0x0000000000001000-0x0000000000001010)  rw-  0x00000074 0x00000010 0x00000003 a.out.PT_LOAD[0]..data
  0xfffffffffffffffe container        [0x0000000000001000-0x0000000000001010)  rw-  0x00000084 0x00000000 0x00000000 a.out.PT_TLS[0]
  0x00000002 zero-fill        [0x0000000000001000-0x0000000000001010)  rw-  0x00000084 0x00000000 0x00000403 a.out.PT_TLS[0]..tbss
  0x00000003 regular                                                   ---  0x00000084 0x00000001 0x00000000 a.out..strtab
  0x00000004 regular                                                   ---  0x00000085 0x0000001f 0x00000000 a.out..shstrtab
```
New output looks like:
```
(lldb) image dump sections a.out
Sections for '/tmp/a.out' (arm):
  SectID             Type                   File Address                             Perm File Off.  File Size  Flags      Section Name
  ------------------ ---------------------- ---------------------------------------  ---- ---------- ---------- ---------- ----------------------------
  0xffffffffffffffff container              [0x0000000000001000-0x0000000000001010)  rw-  0x00000074 0x00000010 0x00000000 a.out.PT_LOAD[0]
  0x0000000000000001 data                   [0x0000000000001000-0x0000000000001010)  rw-  0x00000074 0x00000010 0x00000003 a.out.PT_LOAD[0]..data
  0xfffffffffffffffe container              [0x0000000000001000-0x0000000000001010)  rw-  0x00000084 0x00000000 0x00000000 a.out.PT_TLS[0]
  0x0000000000000002 zero-fill              [0x0000000000001000-0x0000000000001010)  rw-  0x00000084 0x00000000 0x00000403 a.out.PT_TLS[0]..tbss
  0x0000000000000003 regular                                                         ---  0x00000084 0x00000001 0x00000000 a.out..strtab
  0x0000000000000004 regular                                                         ---  0x00000085 0x0000001f 0x00000000 a.out..shstrtab
```
This change is an implementation of
llvm#87367 investigation on
supporting IEEE math operations as intrinsics.
Which was discussed in this RFC:
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

This change adds constraint intrinsics and some lowering cases for
`acos`, `asin`, `atan`, `cosh`, `sinh`, and `tanh`.
The only x86 specific change was for f80.

llvm#70079
llvm#70080
llvm#70081
llvm#70083
llvm#70084
llvm#95966
    
The x86 lowering is going to be done in three pr changes with this being
the first.
A second PR will be put up for Loop Vectorizing and then SLPVectorizer.

The constraint intrinsics is also going to be in multiple parts, but
just 2.
This part covers just the llvm specific changes, part2 will cover clang
specifc changes and legalization for backends than have special
legalization
 requirements like aarch64 and wasm.
f18 current emits an error when an assignment is made to an array
section with a vector subscript, and the array is finalized with a
non-elemental final subroutine. Some other compilers emit this error
because (I think) they want variables to only be finalized in place, not
by a subroutine call involving copy-in & copy-out of the finalized
elements.

Since many other Fortran compilers can handle this case, and there's
nothing in the standards to preclude it, let's downgrade this error
message to a portability warning.

This patch got complicated because the API for the WhyNotDefinable()
utility routine was such that it would return a message only in error
cases, and there was no provision for returning non-fatal messages. It
now returns either nothing, a fatal message, or a non-fatal warning
message, and all of its call sites have been modified to cope.
…m#98374)

We emit an incorrect error message when !DIR$ IGNORE_TKR appears in a
separate module procedure's interface declaration.

Fixes llvm#98210.
This patch updates the clang-tidy checks for llvm-libc to ensure that
the namespace macro used to declare the libc namespace is updated from
LIBC_NAMESPACE to LIBC_NAMESPACE_DECL which by default has hidden
visibility.

Co-authored-by: Prabhu Rajesakeran <[email protected]>
tbaederr and others added 20 commits July 14, 2024 18:02
We need to invert them and use the opposite shift.
This happens a lot for NonTypeTemplateParm decls.
Use -fno-rtti flag to avoid vtables in the runtime library (similarly to asan, dfsan, msan).
Remove unneeded -fPIC from NSAN_CFLAGS.

Fix llvm#98767
…#98601)

Add `MachineOptimizationRemarkEmitterAnalysis` the legacy version
`MachineOptimizationRemarkEmitterPass` is already a wrapper.
They were only called once, or not at all.
For invalid cases (non-vector/complex/...), this should only happen
in error cases such as the attached test case.
areInlineCompatible checks to see if CalleeTLI.OverrideAsUnavailable
is a subset of OverrideAsUnavailable by computing a union of the two
and comparing the union and OverrideAsUnavailable.

The problem is that computing a union involves memory allocations.
This patch removes the need for memory allocations by switching to
BitVector::test.  Note that A.test(B) returns true if A - B is
non-empty.  That is, !A.test(B) is true if A if a subset of B.

The use of BitVector::test here saves 0.20% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.
…lvm#95563)

Added a RISCV overload of `isTruncateFree` to fix the break of vnsrl described in issue llvm#94265.

Fixes llvm#94265
This adds a tablegen pattern to use ORRWrr (mov) as opposed to i64 AND
0xffffffff, as the mov will implicitly clear the upper bits. This can be
seen as a zext(trunc(..)), and could be simpler if it is eliminated.
Add tests with accesses to the same pointer with different types. At the
moment, runtime checks for those accesses are incorrectly based on the
smaller type.
The optimization attributes are mostly noise for the purposes of the test.
Also hoping this fixes https://lab.llvm.org/buildbot/#/builders/193/builds/940,
which for some reason looks like the optimization isn't running.
The current frame might not be a constructor for the object we're
initializing, but a parent frame might.
…lvm#98646)

The plan is to add more TernaryOp in the future (SELECT/VSELECT and FMA in particular)
Use getNameForDiagnostic(), like the CallStackFrame of the current
interpreter.
The same pointer may be accessed with different types and the bound
includes the size of the accessed type to compute the end. Update the
cache to correctly disambiguate between different accessed types.
…lvm#98809)

These may not get canonicalized before conversion to spirv and need to
be handled during vector to spirv conversion. Because spirv does not
support 1-element vectors, we can't emit `spirv.VectorShuffle` and need
to lower this to `spirv.CompositeExtract`.
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.