diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2022-07-22 15:24:54 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2022-07-22 15:24:54 -0400 |
commit | 7068aa98412ade19a34b7ed126f4669f581b2311 (patch) | |
tree | 31e4435d3eab49fd73d57be3d62ba0d06d789b93 /clang/include | |
parent | b5c7213647aae9c456c0a82af46e7dae9e04bf49 (diff) | |
download | llvm-7068aa98412ade19a34b7ed126f4669f581b2311.zip llvm-7068aa98412ade19a34b7ed126f4669f581b2311.tar.gz llvm-7068aa98412ade19a34b7ed126f4669f581b2311.tar.bz2 |
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
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 550029f..7561027 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8037,24 +8037,6 @@ def err_incompatible_qualified_id : Error< "sending type to parameter of incompatible type}0,1" "|%diff{casting $ to incompatible type $|" "casting type to incompatible type}0,1}2">; -def ext_typecheck_convert_pointer_int : ExtWarn< - "incompatible pointer to integer conversion " - "%select{%diff{assigning to $ from $|assigning to different types}0,1" - "|%diff{passing $ to parameter of type $|" - "passing to parameter of different type}0,1" - "|%diff{returning $ from a function with result type $|" - "returning from function with different return type}0,1" - "|%diff{converting $ to type $|converting between types}0,1" - "|%diff{initializing $ with an expression of type $|" - "initializing with expression of different type}0,1" - "|%diff{sending $ to parameter of type $|" - "sending to parameter of different type}0,1" - "|%diff{casting $ to type $|casting between types}0,1}2" - "%select{|; dereference with *|" - "; take the address with &|" - "; remove *|" - "; remove &}3">, - InGroup<IntConversion>; def err_typecheck_convert_pointer_int : Error< "incompatible pointer to integer conversion " "%select{%diff{assigning to $ from $|assigning to different types}0,1" @@ -8072,24 +8054,9 @@ def err_typecheck_convert_pointer_int : Error< "; take the address with &|" "; remove *|" "; remove &}3">; -def ext_typecheck_convert_int_pointer : ExtWarn< - "incompatible integer to pointer conversion " - "%select{%diff{assigning to $ from $|assigning to different types}0,1" - "|%diff{passing $ to parameter of type $|" - "passing to parameter of different type}0,1" - "|%diff{returning $ from a function with result type $|" - "returning from function with different return type}0,1" - "|%diff{converting $ to type $|converting between types}0,1" - "|%diff{initializing $ with an expression of type $|" - "initializing with expression of different type}0,1" - "|%diff{sending $ to parameter of type $|" - "sending to parameter of different type}0,1" - "|%diff{casting $ to type $|casting between types}0,1}2" - "%select{|; dereference with *|" - "; take the address with &|" - "; remove *|" - "; remove &}3">, - InGroup<IntConversion>, SFINAEFailure; +def ext_typecheck_convert_pointer_int : ExtWarn< + err_typecheck_convert_pointer_int.Text>, + InGroup<IntConversion>, DefaultError; def err_typecheck_convert_int_pointer : Error< "incompatible integer to pointer conversion " "%select{%diff{assigning to $ from $|assigning to different types}0,1" @@ -8107,6 +8074,9 @@ def err_typecheck_convert_int_pointer : Error< "; take the address with &|" "; remove *|" "; remove &}3">; +def ext_typecheck_convert_int_pointer : ExtWarn< + err_typecheck_convert_int_pointer.Text>, + InGroup<IntConversion>, DefaultError; def ext_typecheck_convert_pointer_void_func : Extension< "%select{%diff{assigning to $ from $|assigning to different types}0,1" "|%diff{passing $ to parameter of type $|" |