[PATCH] D129881: [C] Strengthen -Wint-conversion to default to an error

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 15 10:37:22 PDT 2022


aaron.ballman created this revision.
aaron.ballman added reviewers: efriedma, jyknight, erichkeane, clang-language-wg.
Herald added subscribers: steakhal, Enna1, kosarev, arphaman, jvesely.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added projects: clang, Sanitizers, clang-tools-extra.
Herald added a subscriber: Sanitizers.

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.

When modifying the diagnostics, I observed that `ext_typecheck_convert_int_pointer` was already marked `SFINAEFailure` but `ext_typecheck_convert_pointer_int` was not. This appeared to be an oversight which I corrected. That resulted in needing a change to not perform SFINAE traps in C mode. If desired, I can split those changes into a separate review, but they felt related enough to this change to be reasonable to roll in here by virtue of changing the behavior of the diagnostic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129881

Files:
  clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m
  clang-tools-extra/test/clang-tidy/checkers/performance/no-int-to-ptr.c
  clang/bindings/python/tests/cindex/test_diagnostics.py
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Analysis/ObjCProperties.m
  clang/test/Analysis/bsd-string.c
  clang/test/Analysis/novoidtypecrash.c
  clang/test/Analysis/null-deref-ps.c
  clang/test/Analysis/number-object-conversion.c
  clang/test/Analysis/number-object-conversion.m
  clang/test/Analysis/pr22954.c
  clang/test/C/drs/dr0xx.c
  clang/test/C/drs/dr2xx.c
  clang/test/CodeGen/2008-03-05-syncPtr.c
  clang/test/CodeGen/2008-07-31-promotion-of-compound-pointer-arithmetic.c
  clang/test/CodeGen/aarch64-mops.c
  clang/test/CodeGen/address-space-cast.c
  clang/test/CodeGen/const-init.c
  clang/test/CodeGen/pointer-arithmetic.c
  clang/test/CodeGen/pointer-to-int.c
  clang/test/CodeGen/statements.c
  clang/test/CodeGen/struct-init.c
  clang/test/CodeGen/vla.c
  clang/test/CodeGenObjC/block-ptr-type-crash.m
  clang/test/CodeGenOpenCL/builtins-generic-amdgcn.cl
  clang/test/FixIt/dereference-addressof.c
  clang/test/FixIt/selector-fixit.m
  clang/test/Misc/serialized-diags.c
  clang/test/Misc/tabstop.c
  clang/test/Modules/config_macros.m
  clang/test/PCH/objc_exprs.m
  clang/test/Parser/implicit-casts.c
  clang/test/Sema/array-init.c
  clang/test/Sema/atomic-ops.c
  clang/test/Sema/block-return.c
  clang/test/Sema/builtin-alloca-with-align.c
  clang/test/Sema/builtin-assume-aligned.c
  clang/test/Sema/builtin-dump-struct.c
  clang/test/Sema/builtins-bpf.c
  clang/test/Sema/builtins.c
  clang/test/Sema/compound-literal.c
  clang/test/Sema/conditional-expr.c
  clang/test/Sema/enum.c
  clang/test/Sema/extern-redecl.c
  clang/test/Sema/format-strings.c
  clang/test/Sema/function-redecl.c
  clang/test/Sema/function.c
  clang/test/Sema/i-c-e.c
  clang/test/Sema/indirect-goto.c
  clang/test/Sema/matrix-type-builtins.c
  clang/test/Sema/nullability.c
  clang/test/SemaObjC/argument-checking.m
  clang/test/SemaObjC/comptypes-7.m
  clang/test/SemaObjC/ivar-lookup-resolution-builtin.m
  clang/test/SemaObjC/message.m
  clang/test/SemaObjC/method-lookup-5.m
  clang/test/SemaObjC/nullability.m
  clang/test/SemaObjC/objc-container-subscripting-3.m
  clang/test/SemaObjC/objc-literal-fixit.m
  clang/test/SemaObjC/signed-char-bool-conversion.m
  clang/test/SemaOpenCL/atomic-ops.cl
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl
  clang/test/VFS/Inputs/external-names.h
  clang/test/VFS/external-names.c
  compiler-rt/test/dfsan/gep.c
  compiler-rt/test/dfsan/sigaction.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129881.445048.patch
Type: text/x-patch
Size: 78033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220715/2e3308e3/attachment-0001.bin>


More information about the cfe-commits mailing list