lint: do not warn about alignment when casting from incomplete struct

This removes a bunch of technically correct but practically useless
warnings from the regular NetBSD build.
This commit is contained in:
rillig 2021-04-17 16:58:04 +00:00
parent 814d2d428a
commit c322b8c5b5
3 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_135.c,v 1.6 2021/04/17 16:52:09 rillig Exp $ */
/* $NetBSD: msg_135.c,v 1.7 2021/04/17 16:58:04 rillig Exp $ */
# 3 "msg_135.c"
// Test for message: converting '%s' to '%s' may cause alignment problem [135]
@ -28,6 +28,10 @@ struct complete {
* from the publicly visible, incomplete 'struct lhash_st' to a private
* implementation type such as 'struct lhash_st_OPENSSL_STRING'.
*
* Before tree.c 1.277 from 2021-04-17, lint warned about this, even though
* there was not enough evidence that there really was an alignment problem,
* resulting in many false positives.
*
* See openssl/lhash.h.
*/
void
@ -35,6 +39,6 @@ pointer_to_structs(struct incomplete *incomplete)
{
struct complete *complete;
complete = (struct complete *)incomplete; /* expect: 135 */
complete = (struct complete *)incomplete;
sink(complete);
}

View File

@ -1,3 +1,2 @@
msg_135.c(15): warning: converting 'pointer to const unsigned char' to 'pointer to const unsigned int' may cause alignment problem [135]
msg_135.c(38): warning: converting 'pointer to incomplete struct incomplete' to 'pointer to struct complete' may cause alignment problem [135]
msg_135.c(20): warning: struct incomplete never defined [233]

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.276 2021/04/10 18:06:53 rillig Exp $ */
/* $NetBSD: tree.c,v 1.277 2021/04/17 16:58:04 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.276 2021/04/10 18:06:53 rillig Exp $");
__RCSID("$NetBSD: tree.c,v 1.277 2021/04/17 16:58:04 rillig Exp $");
#endif
#include <float.h>
@ -2081,7 +2081,8 @@ check_pointer_conversion(tnode_t *tn, type_t *ntp)
return;
}
if (hflag && alignment_in_bits(nstp) > alignment_in_bits(ostp)) {
if (hflag && alignment_in_bits(nstp) > alignment_in_bits(ostp) &&
!is_incomplete(ostp)) {
/* converting '%s' to '%s' may cause alignment problem */
warning(135, type_name(otp), type_name(ntp));
}