llvm-project/clang/test/Frontend
Nick Desaulniers 846e562dcc [Clang] add support for error+warning fn attrs
Add support for the GNU C style __attribute__((error(""))) and
__attribute__((warning(""))). These attributes are meant to be put on
declarations of functions whom should not be called.

They are frequently used to provide compile time diagnostics similar to
_Static_assert, but which may rely on non-ICE conditions (ie. relying on
compiler optimizations). This is also similar to diagnose_if function
attribute, but can diagnose after optimizations have been run.

While users may instead simply call undefined functions in such cases to
get a linkage failure from the linker, these provide a much more
ergonomic and actionable diagnostic to users and do so at compile time
rather than at link time. Users instead may be able use inline asm .err
directives.

These are used throughout the Linux kernel in its implementation of
BUILD_BUG and BUILD_BUG_ON macros. These macros generally cannot be
converted to use _Static_assert because many of the parameters are not
ICEs. The Linux kernel still needs to be modified to make use of these
when building with Clang; I have a patch that does so I will send once
this feature is landed.

To do so, we create a new IR level Function attribute, "dontcall" (both
error and warning boil down to one IR Fn Attr).  Then, similar to calls
to inline asm, we attach a !srcloc Metadata node to call sites of such
attributed callees.

The backend diagnoses these during instruction selection, while we still
know that a call is a call (vs say a JMP that's a tail call) in an arch
agnostic manner.

The frontend then reconstructs the SourceLocation from that Metadata,
and determines whether to emit an error or warning based on the callee's
attribute.

Link: https://bugs.llvm.org/show_bug.cgi?id=16428
Link: https://github.com/ClangBuiltLinux/linux/issues/1173

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D106030
2021-08-25 10:34:18 -07:00
..
Inputs [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist= 2021-05-04 10:24:00 -04:00
Weverything.c
Wno-everything.c
aarch64-target-cpu.c [clang][llvm] Obsolete Exynos M1 and M2 2019-10-30 15:02:59 -05:00
absolute-paths-symlinks.c [clang][test] Minor fixes in testcase absolute-paths-symlinks.c 2019-12-26 09:33:21 +01:00
absolute-paths-windows.test Do not resolve directory junctions for `-fdiagnostics-absolute-paths` on Windows. 2019-05-24 04:46:22 +00:00
absolute-paths.c [Diagnostics] Try to improve warning message for -Wreturn-type 2019-11-09 17:54:58 +01:00
aix-unsupported.c [clang][AIX] Implement ABIInfo and TargetCodeGenInfo for AIX 2020-05-19 15:00:48 +00:00
ast-codegen.c Recommit #2 "[Driver] Default to -fno-common for all targets" 2020-03-09 19:57:03 +00:00
ast-main.c [darwin] parse the SDK settings from SDKSettings.json if it exists and 2018-12-17 19:19:15 +00:00
ast-main.cpp Fixed more -Wreturn-type tests 2019-11-09 18:13:51 +01:00
backend-attribute-error-warning-optimize.c [Clang] add support for error+warning fn attrs 2021-08-25 10:34:18 -07:00
backend-attribute-error-warning.c [Clang] add support for error+warning fn attrs 2021-08-25 10:34:18 -07:00
backend-diagnostic.c Improve clang -Wframe-larger-than= diagnostic 2021-06-22 11:20:49 -07:00
cc1-return-codes.c [test] Use %clang_cc1 instead of %clang -cc1 2019-09-27 05:37:06 +00:00
clang-abi-compat.cpp Make test/Frontend/clang-abi-compat.cpp pass when the version goes to 8 2018-08-01 13:19:14 +00:00
compiler-options-dump.cpp Add a new driver mode to dump compiler feature and extension options. 2018-05-31 13:57:09 +00:00
cpp-output.c
crash-diagnostic-renderer.cpp [clang][Frontend] Fix a crash in DiagnosticRenderer. 2021-02-17 09:02:49 +01:00
darwin-eabi.c
darwin-version.c
dependency-gen-escaping.c Print correctly dependency paths on Windows 2018-09-13 14:27:32 +00:00
dependency-gen-extradeps-phony.c Fix emission of phony dependency targets when adding extra deps 2018-05-29 13:07:58 +00:00
dependency-gen-has-include.c Re-land Remove REQUIRES:shell from tests that pass for me on Windows 2019-09-10 20:15:45 +00:00
dependency-gen-symlink.c Track skipped files in dependency scanning. 2018-05-01 23:59:33 +00:00
dependency-gen-windows-duplicates.c [clang] In DependencyCollector on Windows, ignore case and separators when discarding duplicate dependency file paths. 2021-05-17 10:32:52 -04:00
dependency-gen.c [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist= 2021-05-04 10:24:00 -04:00
dependency-generation-crash.c
diagnostics-option-names.c [Driver] Flip the CC1 default of -fdiagnostics-show-option 2020-03-31 21:59:27 -07:00
diagnostics-order.c [clang][cli] Parse Lang and CodeGen options separately 2021-01-19 09:52:46 +01:00
disable-output.c
embed-bitcode-noopt.c [test] Add {{.*}} to make ELF tests immune to dso_local/dso_preemptable/(none) differences 2020-12-31 00:27:11 -08:00
embed-bitcode-noopt.ll Add REQUIRES to embed-bitcode-noopt.ll 2020-09-23 10:13:09 -07:00
embed-bitcode.ll Set alignment of .llvmbc and .llvmcmd to 1 2020-08-29 18:27:34 -07:00
exceptions.c
fixed_point_add.c [Fixed Point] Use FixedPointBuilder to codegen fixed-point IR. 2020-08-24 14:37:07 +02:00
fixed_point_add_const.c Refactor most of the fixed-point tests. 2020-08-20 10:30:05 +02:00
fixed_point_bit_widths.c [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals 2018-06-20 17:19:40 +00:00
fixed_point_comparisons.c [Fixed Point Arithmetic] Fixed Point Comparisons 2019-02-21 20:50:09 +00:00
fixed_point_compound.c [Fixed Point] Add codegen for conversion between fixed-point and floating point. 2021-01-12 13:53:01 +01:00
fixed_point_conversions.c [Fixed Point] Add codegen for conversion between fixed-point and floating point. 2021-01-12 13:53:01 +01:00
fixed_point_conversions_const.c [Fixed Point] Add fixed-point to floating point cast types and consteval. 2020-10-13 13:26:56 +02:00
fixed_point_conversions_half.c [Fixed Point] Add codegen for conversion between fixed-point and floating point. 2021-01-12 13:53:01 +01:00
fixed_point_crash.c [AST] Fix certain consteval assignment and comma operator issues with fixed-point types. 2020-06-26 13:38:11 +02:00
fixed_point_declarations.c [Fixed Point Arithmetic] Fixed Point Constant 2018-08-06 16:42:37 +00:00
fixed_point_div.c [Fixed Point] Use FixedPointBuilder to codegen fixed-point IR. 2020-08-24 14:37:07 +02:00
fixed_point_div_const.c Refactor most of the fixed-point tests. 2020-08-20 10:30:05 +02:00
fixed_point_errors.c [Fixed Point] Add fixed-point to floating point cast types and consteval. 2020-10-13 13:26:56 +02:00
fixed_point_errors.cpp [Fixed Point Arithmetic] Fix for bug where integer literals could be treated as fixed point literals 2018-07-17 14:58:49 +00:00
fixed_point_mul.c [Fixed Point] Use FixedPointBuilder to codegen fixed-point IR. 2020-08-24 14:37:07 +02:00
fixed_point_mul_const.c Refactor most of the fixed-point tests. 2020-08-20 10:30:05 +02:00
fixed_point_not_enabled.c [Fixed Point Arithmetic] Fix for bug where integer literals could be treated as fixed point literals 2018-07-17 14:58:49 +00:00
fixed_point_same_fbits.c [Fixed Point Arithmetic] Rename `-fsame-fbits` flag 2018-06-29 17:08:19 +00:00
fixed_point_shift.c [Fixed Point] Add codegen for fixed-point shifts. 2020-08-24 14:37:16 +02:00
fixed_point_shift_const.c [Fixed Point] Add codegen for fixed-point shifts. 2020-08-24 14:37:16 +02:00
fixed_point_sub.c [Fixed Point] Use FixedPointBuilder to codegen fixed-point IR. 2020-08-24 14:37:07 +02:00
fixed_point_sub_const.c Add triples to fixed-point tests which lacked them. 2020-08-20 15:36:15 +02:00
fixed_point_to_bool.c [Fixed Point Arithmetic] Refactor fixed point casts 2018-10-26 16:12:12 +00:00
fixed_point_unary.c Reapply [ConstantFold] Fold more operations to poison 2021-05-13 16:04:12 +02:00
fixed_point_unknown_conversions.c [Fixed Point] Add fixed-point to floating point cast types and consteval. 2020-10-13 13:26:56 +02:00
force-include-not-found.c
ftime-report-template-decl.cpp Improve checks in test/Frontend/ftime-report-template-decl.cpp 2018-04-23 18:05:35 +00:00
fwarn-stack-size.c [IR] convert warn-stack-size from module flag to fn attr 2021-06-21 15:09:25 -07:00
gnu-inline.c Add -fgnuc-version= to control __GNUC__ and other GCC macros 2019-10-10 21:04:25 +00:00
gnu-mcount.c Move EntryExitInstrumentation pass location 2021-03-01 10:08:10 -08:00
hexagon-target-basic.c
iframework.c
include-duplicate-removal.c
int128.cpp
invalid-cxx-abi.cpp Correct a lot of diagnostic wordings for the driver 2021-08-05 07:04:55 -04:00
invalid-o-level.c
ir-support-codegen.ll
ir-support-errors.ll
ir-support.c
lit.local.cfg Do not resolve directory junctions for `-fdiagnostics-absolute-paths` on Windows. 2019-05-24 04:46:22 +00:00
macro_defined_type.cpp [Sema] Add MacroQualified case for FunctionTypeUnwrapper 2019-11-12 16:22:13 -08:00
macros.c
mfpmath.c
minimize_source_to_dependency_directives.c Add clang source minimizer that reduces source to directives 2019-06-03 22:59:17 +00:00
mips-long-double.c
noderef.c [clang] Fix noderef for AddrOf on MemberExpr 2020-12-07 14:48:41 -08:00
noderef.cpp Ignore noderef attribute in unevaluated context 2020-11-23 08:10:35 -05:00
noderef_on_non_pointers.m [Sema/Attribute] Check for noderef attribute 2018-12-06 01:05:54 +00:00
noderef_templates.cpp [Sema/Attribute] Check for noderef attribute 2018-12-06 01:05:54 +00:00
nostdlib-for-asmpp.s [test] Use %clang_cc1 instead of %clang -cc1 2019-09-27 05:37:06 +00:00
objc-bool-is-bool.m
opencl.cl [OpenCL] Clang diagnostics allow reporting C++ for OpenCL version. 2021-08-13 13:55:22 +01:00
optimization-remark-analysis.c
optimization-remark-extra-analysis.c
optimization-remark-line-directive.c [InlineAdvisor] Add single quotes around caller/callee names 2021-08-10 11:51:31 -07:00
optimization-remark-new-pm.c [InlineAdvisor] Add single quotes around caller/callee names 2021-08-10 11:51:31 -07:00
optimization-remark-options.c [Clang] Fix line numbers in CHECK lines. 2021-03-29 17:37:48 +01:00
optimization-remark-with-hotness-new-pm.c [InlineAdvisor] Add single quotes around caller/callee names 2021-08-10 11:51:31 -07:00
optimization-remark-with-hotness.c [InlineAdvisor] Add single quotes around caller/callee names 2021-08-10 11:51:31 -07:00
optimization-remark.c [InlineAdvisor] Add single quotes around caller/callee names 2021-08-10 11:51:31 -07:00
output-paths.c [test] Use host platform specific error message substitution in lit tests 2021-01-29 07:16:30 -05:00
plugin-annotate-functions.c Fix clang/test/Frontend/plugin-annotate-functions.c 2021-04-21 14:00:38 +01:00
plugin-attribute.cpp [clang] Fix expected errors in plugin attribute example 2020-12-21 16:47:23 +00:00
plugin-call-super.cpp Add a call super attribute plugin example 2020-11-20 08:51:12 -05:00
plugin-delayed-template.cpp
plugin-unknown.c Validate -add-plugin arguments. 2019-01-03 18:26:06 +00:00
plugin-vs-debug-info.cpp
plugins.c
pp-only-no-editor-placeholders.c
preprocessed-input.i
preprocessed-output-macro-first-token.c
print-header-includes.c [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist= 2021-05-04 10:24:00 -04:00
profile-sample-use-loc-tracking.c
region-pragmas.c Always allow "#pragma region". 2018-01-27 00:25:29 +00:00
remarks-hotness.cpp [InlineAdvisor] Add single quotes around caller/callee names 2021-08-10 11:51:31 -07:00
remove-file-on-signal.c
rewrite-includes-bom.c
rewrite-includes-cli-include.c actually also compile output in tests for -frewrite-includes 2019-09-18 19:12:14 +00:00
rewrite-includes-conditions.c fix build, adjust test also for Windows path separator 2019-09-18 21:41:45 +00:00
rewrite-includes-eof.c
rewrite-includes-filenotfound.c
rewrite-includes-header-cmd-line.c
rewrite-includes-invalid-hasinclude.c
rewrite-includes-line-markers.c
rewrite-includes-macros.cpp [Windows] Add test coverage for line endings when rewriting includes 2021-04-06 15:38:19 -04:00
rewrite-includes-messages.c Use POSIX argument syntax in test rewrite-includes-messages.c 2018-01-04 23:03:48 +00:00
rewrite-includes-missing.c
rewrite-includes-modules.c
rewrite-includes-warnings.c do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614) 2019-09-16 19:18:37 +00:00
rewrite-includes.c fix build, adjust test also for Windows path separator 2019-09-18 21:41:45 +00:00
rewrite-macros.c
round-trip-cc1-args.c Correct a lot of diagnostic wordings for the driver 2021-08-05 07:04:55 -04:00
source-col-map.c [Driver] Don't pass -fmessage-length=0 to CC1 2020-03-31 17:12:08 -07:00
stats-file.c [test] Use host platform specific error message substitution in lit tests 2021-01-29 07:16:30 -05:00
stdin-input.c Fix buildbot failure from r373217 (don't match metadata id exactly) 2019-09-30 17:26:48 +00:00
stdin.c
stdlang.c [OpenCL] C++ for OpenCL version 2021 introduced to command line. 2021-08-18 10:08:59 +01:00
sycl-aux-triple.cpp [SYCL] Rework the SYCL driver options 2021-03-17 08:27:19 -04:00
sycl.cpp [SYCL] Rework the SYCL driver options 2021-03-17 08:27:19 -04:00
system-header-line-directive-ms-lineendings.c
system-header-line-directive.c
system-header-prefix.c
trigraphs.cpp [SystemZ][z/OS] enable trigraphs by default on z/OS 2020-08-13 16:02:07 -04:00
undef.c
unknown-arg.c lld-link, clang: Treat non-existent input files as possible spellos for option flags 2019-05-23 17:58:33 +00:00
unknown-pragmas.c
valid-cxx-abi.cpp [clang][test] Update -fc++-abi tests 2021-05-04 15:53:00 -07:00
verify-any-file.c [clang][VerifyDiagnosticConsumer] Support filename wildcards 2020-05-14 15:15:49 -07:00
verify-any-file.h [clang][VerifyDiagnosticConsumer] Support filename wildcards 2020-05-14 15:15:49 -07:00
verify-directive.h
verify-fatal.c
verify-ignore-unexpected.c
verify-marker.c [verify] Add support for location markers in directives. 2019-04-13 04:33:39 +00:00
verify-marker.h [verify] Add support for location markers in directives. 2019-04-13 04:33:39 +00:00
verify-prefixes.c [VerifyDiagnosticConsumer] support -verify=<prefixes> 2017-12-16 02:23:22 +00:00
verify-unknown-arg.c
verify.c
verify2.c
verify2.h
verify3.c
warn-device-init-fun.cu [HIP] Add option -fgpu-allow-device-init 2019-10-22 16:06:20 -04:00
warning-mapping-1.c
warning-mapping-2.c Fix the behavior of clang's -w flag. 2019-01-29 19:33:48 +00:00
warning-mapping-3.c
warning-mapping-4.c Fix the behavior of clang's -w flag. 2019-01-29 19:33:48 +00:00
warning-mapping-5.c Fix the behavior of clang's -w flag. 2019-01-29 19:33:48 +00:00
warning-mapping-6.c Fix the behavior of clang's -w flag. 2019-01-29 19:33:48 +00:00
warning-options.cpp [Sema] Special case -Werror-implicit-function-declaration and reject other -Werror- 2020-11-05 10:25:30 -08:00
warning-poison-system-directories.c Reland r371785: Add -Wpoison-system-directories warning 2019-09-13 18:00:51 +00:00
windows-exceptions.cpp [clang][cli] Squash multiple cc1 -fxxx-exceptions flags into single -exception-model=xxx option 2020-12-15 10:15:58 +01:00
windows-nul.c
x86-embed-bitcode.ll Set alignment of .llvmbc and .llvmcmd to 1 2020-08-29 18:27:34 -07:00
x86-target-cpu.c [X86] Update tests for znver3 2021-01-07 11:51:50 +05:30
x86_64-nacl-types.cpp