Commit Graph

47 Commits

Author SHA1 Message Date
Aaron Ballman
5be51acbf0 Speculatively fix the test bots
This should hopefully fix the issues found on Linux hosts like:
https://lab.llvm.org/buildbot#builders/109/builds/49321
https://lab.llvm.org/buildbot/#/builders/139/builds/30061
2022-10-25 11:35:53 -04:00
Aaron Ballman
cb088e8c3a Add more C99 DR test cases and update the status page
This mostly completes the C99 set of DRs, though there are a few still
marked as "unknown".
2022-10-25 11:14:52 -04:00
Aaron Ballman
0de10a60af Fix a failing C DR test case found by post-commit CI
This should address the failure found by:
https://lab.llvm.org/buildbot/#/builders/231/builds/4152
2022-10-24 16:25:10 -04:00
Aaron Ballman
5635f005f9 Fix failing test case
This amends f43ef6b2dc with some warnings
that got dropped before I commit the test.
2022-10-24 15:19:41 -04:00
Aaron Ballman
f43ef6b2dc Update the status of more C99 DRs
This adds test coverage and updates the related entries for five more
C99 DRs.
2022-10-24 15:11:04 -04:00
Aaron Ballman
3a31970ee2 [C2x] Implement support for nullptr and nullptr_t
This introduces support for nullptr and nullptr_t in C2x mode. The
proposal accepted by WG14 is:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm

Note, there are quite a few incompatibilities with the C++ feature in
some of the edge cases of this feature. Therefore, there are some FIXME
comments in tests for testing behavior that might change after WG14 has
resolved national body comments (a process we've not yet started). So
this implementation might change slightly depending on the resolution
of comments. This is called out explicitly in the release notes as
well.

Differential Revision: https://reviews.llvm.org/D135099
2022-10-14 10:06:02 -04:00
Aaron Ballman
60727d8569 [C2x] implement typeof and typeof_unqual
This implements WG14 N2927 and WG14 N2930, which together define the
feature for typeof and typeof_unqual, which get the type of their
argument as either fully qualified or fully unqualified. The argument
to either operator is either a type name or an expression. If given a
type name, the type information is pulled directly from the given name.
If given an expression, the type information is pulled from the
expression. Recursive use of these operators is allowed and has the
expected behavior (the innermost operator is resolved to a type, and
that's used to resolve the next layer of typeof specifier, until a
fully resolved type is determined.

Note, we already supported typeof in GNU mode as a non-conforming
extension and we are *not* exposing typeof_unqual as a non-conforming
extension in that mode, nor are we exposing typeof or typeof_unqual as
a nonconforming extension in other language modes. The GNU variant of
typeof supports a form where the parentheses are elided from the
operator when given an expression (e.g., typeof 0 i = 12;). When in C2x
mode, we do not support this extension.

Differential Revision: https://reviews.llvm.org/D134286
2022-09-28 13:27:52 -04:00
Aaron Ballman
91babd3516 Update the status of a few more C99 DRs 2022-09-26 08:20:56 -04:00
Jun Zhang
e07ead85a3
[Clang] Warn when trying to dereference void pointers in C
Previously we only have an extension that warn void pointer deferencing
in C++, but for C we did nothing.

C2x 6.5.3.2p4 says The unary * operator denotes indirection. If it points
to an object, the result is an lvalue designating the object. However, there
is no way to form an lvalue designating an object of an incomplete type as
6.3.2.1p1 says "an lvalue is an expression (with an object type other than
void)", so the behavior is undefined.

Fixes https://github.com/llvm/llvm-project/issues/53631

Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D134461
2022-09-24 22:18:04 +08:00
Aaron Ballman
9018fa1745 Update the C status page for WG14 N2359
We don't yet implement this paper, so this adds a basic test
demonstrating that.
2022-09-22 13:05:49 -04:00
Evgeny Shulgin
3285f9a239 [Clang] Support case and default labels at end of compound statement
Direct continuation of https://reviews.llvm.org/D133887

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D134207
2022-09-21 19:37:22 +00:00
Aaron Ballman
b63b4d8966 Add tests & update the C99 DR statuses for dr315 and dr316 2022-09-21 15:33:03 -04:00
Aaron Ballman
a244194f73 Add additional test coverage for C2x N2508
This spotted a mistake with the original patch, so it puts the status
back to "partial" in the C status tracking page.

This amends 510383626f.
2022-09-19 07:52:07 -04:00
Aaron Ballman
5d92d0b0f8 Correctly diagnose use of long long literals w/o a suffix
We would diagnose use of `long long` as an extension in C89 and C++98
modes when the user spelled the type `long long` or used the `LL`
literal suffix, but failed to diagnose when the literal had no suffix
but required a `long long` to represent the value.
2022-09-17 07:55:10 -04:00
Aaron Ballman
d7e06d5675 Update the status of some more C99 features
This also adds some test coverage to demonstrate we implement what was
standardized.
2022-08-17 08:11:56 -04:00
Aaron Ballman
ba79c2a250 Update the implementation status of some C11 features
This also starts to add some test coverage for specific papers to
validate conformance against.
2022-08-13 10:17:47 -04:00
Aaron Ballman
486a3c4662 Update the status of some more C DRs
Update some of the C99-era DRs starting in the 300s.
2022-08-06 11:53:40 -04:00
Muhammad Usman Shahid
76476efd68 Rewording "static_assert" diagnostics
This patch rewords the static assert diagnostic output. Failing a
_Static_assert in C should not report that static_assert failed. This
changes the wording to be more like GCC and uses "static assertion"
when possible instead of hard coding the name. This also changes some
instances of 'static_assert' to instead be based on the token in the
source code.

Differential Revision: https://reviews.llvm.org/D129048
2022-07-25 07:22:54 -04:00
Aaron Ballman
7068aa9841 Strengthen -Wint-conversion to default to an error
Clang has traditionally allowed C programs to implicitly convert
integers to pointers and pointers to integers, despite it not being
valid to do so except under special circumstances (like converting the
integer 0, which is the null pointer constant, to a pointer). In C89,
this would result in undefined behavior per 3.3.4, and in C99 this rule
was strengthened to be a constraint violation instead. Constraint
violations are most often handled as an error.

This patch changes the warning to default to an error in all C modes
(it is already an error in C++). This gives us better security posture
by calling out potential programmer mistakes in code but still allows
users who need this behavior to use -Wno-error=int-conversion to retain
the warning behavior, or -Wno-int-conversion to silence the diagnostic
entirely.

Differential Revision: https://reviews.llvm.org/D129881
2022-07-22 15:24:54 -04:00
Erich Keane
1da3119025 Revert "Rewording the "static_assert" to static assertion"
Looks like we again are going to have problems with libcxx tests that
are overly specific in their dependency on clang's diagnostics.

This reverts commit 6542cb55a3.
2022-07-21 06:40:14 -07:00
Muhammad Usman Shahid
6542cb55a3 Rewording the "static_assert" to static assertion
This patch is basically the rewording of the static assert statement's
output(error) on screen after failing. Failing a _Static_assert in C
should not report that static_assert failed. It’d probably be better to
reword the diagnostic to be more like GCC and say “static assertion”
failed in both C and C++.

consider a c file having code

_Static_assert(0, "oh no!");

In clang the output is like:

<source>:1:1: error: static_assert failed: oh no!
_Static_assert(0, "oh no!");
^              ~
1 error generated.
Compiler returned: 1

Thus here the "static_assert" is not much good, it will be better to
reword it to the "static assertion failed" to more generic. as the gcc
prints as:

<source>:1:1: error: static assertion failed: "oh no!"
    1 | _Static_assert(0, "oh no!");
          | ^~~~~~~~~~~~~~
          Compiler returned: 1

The above can also be seen here. This patch is about rewording
the static_assert to static assertion.

Differential Revision: https://reviews.llvm.org/D129048
2022-07-21 06:34:14 -07:00
Mitch Phillips
041d4012e4 Revert "Rewording "static_assert" diagnostics"
This reverts commit b7e77ff25f.

Reason: Broke sanitizer builds bots + libcxx. 'static assertion
expression is not an integral constant expression'. More details
available in the Phabricator review: https://reviews.llvm.org/D129048
2022-07-14 10:59:20 -07:00
Muhammad Usman Shahid
b7e77ff25f Rewording "static_assert" diagnostics
This patch rewords the static assert diagnostic output. Failing a
_Static_assert in C should not report that static_assert failed. This
changes the wording to be more like GCC and uses "static assertion"
when possible instead of hard coding the name. This also changes some
instances of 'static_assert' to instead be based on the token in the
source code.

Differential Revision: https://reviews.llvm.org/D129048
2022-07-14 07:47:37 -04:00
Aaron Ballman
2346d19a26 Speculatively fix this C DR test
There is a failing bot:
http://45.33.8.238/macm1/40002/step_7.txt

It looks to be failing because of a regex and how it handles whitespace,
so modifying the CHECK line slightly to account for that.
2022-07-12 15:18:03 -04:00
Aaron Ballman
514dd3c3c3 Update the status for more C DRs
This mostly finishes the DRs in the 200s. There are a few DRs left
which will require more thought and work to test.
2022-07-12 14:06:39 -04:00
Aaron Ballman
548f3f9061 Update the status & add tests for some more C99 DRs 2022-07-06 14:34:36 -04:00
Aaron Ballman
6450daddd2 Test a few more C99 DRs
This updates the status for another 8 DRs.
2022-07-01 13:54:11 -04:00
Aaron Ballman
ac8dab8e09 Add some more expected warnings to this C99 DR test
This should address the issue found by:
https://lab.llvm.org/buildbot/#/builders/171/builds/16835
2022-07-01 08:11:46 -04:00
Aaron Ballman
83fdf0c34e Ensure that the generic associations aren't redundant
This should hopefully address the test failure found in:
https://lab.llvm.org/buildbot/#/builders/171/builds/16833
2022-07-01 07:48:59 -04:00
Aaron Ballman
14035d5147 Fix this C99 DR to be more robust
This should fix the following test issue on ARM:
https://lab.llvm.org/buildbot/#/builders/171/builds/16815
2022-07-01 07:33:37 -04:00
Hubert Tong
6bd53df9b6 [clang][NFC][tests] dr208.c optional signext handling
Fixes llvm/llvm-project#56325.
2022-07-01 00:03:58 -04:00
Corentin Jabot
da1609ad73 Improve the formatting of static_assert messages
Display 'static_assert failed: message' instead of
'static_assert failed "message"' to be consistent
with other implementations and be slightly more
readable.

Reviewed By: #libc, aaron.ballman, philnik, Mordante

Differential Revision: https://reviews.llvm.org/D128844
2022-06-30 23:59:21 +02:00
Reid Kleckner
56dc4dbe45 Fix test expectation positioning relative to FIXME comment
This new test was failing because the line number delta wasn't right.
2022-06-30 14:08:25 -07:00
Aaron Ballman
cce06da1ec Test and document some C99 DRs
This captures the first 15 or so DRs in C99
2022-06-30 15:46:47 -04:00
Corentin Jabot
a774ba7f60 Revert "Improve handling of static assert messages."
This reverts commit 870b6d2183.

This seems to break some libc++ tests, reverting while investigating
2022-06-29 00:03:23 +02:00
Corentin Jabot
870b6d2183 Improve handling of static assert messages.
Instead of dumping the string literal (which
quotes it and escape every non-ascii symbol),
we can use the content of the string when it is a
8 byte string.

Wide, UTF-8/UTF-16/32 strings are still completely
escaped, until we clarify how these entities should
behave (cf https://wg21.link/p2361).

`FormatDiagnostic` is modified to escape
non printable characters and invalid UTF-8.

This ensures that unicode characters, spaces and new
lines are properly rendered in static messages.
This make clang more consistent with other implementation
and fixes this tweet
https://twitter.com/jfbastien/status/1298307325443231744 :)

Of note, `PaddingChecker` did print out new lines that were
later removed by the diagnostic printing code.
To be consistent with its tests, the new lines are removed
from the diagnostic.

Unicode tables updated to both use the Unicode definitions
and the Unicode 14.0 data.

U+00AD SOFT HYPHEN is still considered a print character
to match existing practices in terminals, in addition of
being considered a formatting character as per Unicode.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D108469
2022-06-28 22:26:00 +02:00
Aaron Ballman
313f9cd81d Update statuses and add tests for C89 DRs
This mostly finishes the DRs for C89, though there are still a few
outliers which remain. It also corrects some of the statuses of DRs
where it's not clear if it was fully resolved by the committee or not.

As a drive-by, it also adds -fsyntax-only to the tests which are
verifying diagnostic results. This was previously missed by accident.
2022-06-28 10:29:20 -04:00
Aaron Ballman
10822857b7 Rolling back tests for WG14 DR145
Several build bots are failing with surprising behavior, so it's less
clear whether we do or don't implement this DR properly.

https://lab.llvm.org/buildbot/#/builders/91/builds/10454
https://lab.llvm.org/buildbot/#/builders/109/builds/40668
https://lab.llvm.org/buildbot/#/builders/139/builds/23334
2022-06-15 15:37:14 -04:00
Aaron Ballman
61a649ca35 Update the status of more C DRs
This adds information for DRs 126 through 146.
2022-06-15 15:25:47 -04:00
Aaron Ballman
1896df18cc Correct the behavior of this test for non-Windows targets
This should address build failures like:
https://lab.llvm.org/buildbot/#/builders/188/builds/14980
https://lab.llvm.org/buildbot/#/builders/171/builds/15515
https://lab.llvm.org/buildbot/#/builders/91/builds/9877
2022-06-03 09:00:05 -04:00
Aaron Ballman
3472b6eb0a Updating more entries in the C DR Status page
Adds test coverage or information for ~25 more C DRs.
2022-06-03 08:29:06 -04:00
Aaron Ballman
0b46121c41 Update more DR status information for C.
This adds new files to track DRs 100-199 and 400-499, but the file
contents are still a work in progress. It also updates the associated
status in the DR tracking page.
2022-06-02 09:32:44 -04:00
Aaron Ballman
681c50c62e Improve the strict prototype diagnostic behavior
Post-commit feedback on https://reviews.llvm.org/D122895 pointed out
that the diagnostic wording for some code was using "declaration" in a
confusing way, such as:

int foo(); // warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x

int foo(int arg) { // warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x
  return 5;
}

And that we had other minor issues with the diagnostics being somewhat
confusing.

This patch addresses the confusion by reworking the implementation to
be a bit more simple and a bit less chatty. Specifically, it changes
the warning and note diagnostics to be able to specify "declaration" or
"definition" as appropriate, and it changes the function merging logic
so that the function without a prototype is always what gets warned on,
and the function with a prototype is sometimes what gets noted.
Additionally, when diagnosing a K&R C definition that is preceded by a
function without a prototype, we don't note the prior declaration, we
warn on it because it will also be changing behavior in C2x.

Differential Revision: https://reviews.llvm.org/D125814
2022-05-26 08:35:56 -04:00
Aaron Ballman
f96aa834d7 Test C DR conformance (part three of many)
This adds more of the tests for the first 100 DRs in C and updates
their status on the status page.
2022-05-25 08:18:16 -04:00
Aaron Ballman
202a4fde2b Test more C DR conformance (part two of many)
This continues the work started earlier at filling our the C DR status
page based on test coverage.
2022-05-22 13:37:30 -04:00
Aaron Ballman
36fde81f93 Fix failing test bots from df46fb4055
Should fix bots like:
https://lab.llvm.org/buildbot/#/builders/188/builds/14403
https://lab.llvm.org/buildbot/#/builders/171/builds/14928
https://lab.llvm.org/buildbot/#/builders/123/builds/10852
(and others)
2022-05-21 16:10:37 -04:00
Aaron Ballman
df46fb4055 Test C DR conformance (part one of many)
This starts to fill out the C DR status page with information
determined from tests. It also starts to add some test coverage for the
DRs we can add tests for (some are difficult as not all C DRs involve
questions about code and some DRs are about the behavior of linking
multiple TUs together).

Note: there is currently no automation for filling out the HTML page
from test coverage like there is for the C++ DRs, but this commit
attempts to use a similar comment style in case we want to add such a
script in the future.
2022-05-21 15:02:46 -04:00