// Copyright (c) 2013-2020 Varnish Software AS
// SPDX-License-Identifier: BSD-2-Clause
// See LICENSE file for full text of license

/*
 * Toplevel control file for FlexeLint
 */

//d__flexelint_v9__=1
+fan

// No automatic custody
-ffc

-hm4

///////////////////////////////////////////////////////////////////////
// electives
//+e9*
-e904
-e935
-e955
-e956
//+e958   // report internal struct padding
//+e959   // report struct tail/size padding
-e960
-e961
-efile(966, "/usr/include/*")	// unused indir include
-efile(966, "../../include/tbl/*")
-e964
-e970
-e971
-e9012
-e9021
-e9022
-e9023
-e9024
-e9026
-e9034
-e9037
-e9042
-e9048
-e9050
-e9051
-e9067
+e9071	// defined macro '...' is reserved to the compiler
+e9075	// external symbol without declaration
-esym(9075, main)
-e9085
-e9105
-e9107
-e9109
-e9113
-e9131
-e9132
-e9133
-e9136
-e9140
-e9141
-e9147	// we dont use & on func_pointers
-e9149
-e9158
-e9159
-e9165
///////////////////////////////////////////////////////////////////////


// This does not work with pcre2.h, the injected /* lint ... */ comments
// interfere with macro argument concatenation.  Clear flexelint bug
// because it does not happen when run with -p
// -emacro((835),*)	// A zero has been given as ___ argument to operator '___

-e835	// A zero has been given as ___ argument to operator '___

///////////////////////////////////////////////////////////////////////
// build/config related

-efile(451, "tbl/*.h")		// No include guard
-efile(537, "tbl/*.h")		// Repeated include
-efile(967, "tbl/*.h")		// No include guard

-efile(451, "../../include/vut_options.h")		// No include guard
-efile(451, "../../include/vapi/vapi_options.h")	// No include guard

-efile(451, ../../config.h)	// No include guard
-efile(766, ../../config.h)	// Header file '___' not used in module '___'

+libh(../../config.h)

-esym(768, vmod_priv)	// global struct member '___' (___) not referenced

///////////////////////////////////////////////////////////////////////
// Thread/locking, too many false positives still
-e454		// A thread mutex has been locked but not unlocked___
-e455		// A thread mutex that had not been locked is being unlocked
-e456		// Two execution paths are being combined with different mutex lock states
-e457		// unprotected write access
-e458		// unprotected access
-e459		// unprotected access

///////////////////////////////////////////////////////////////////////
// General stylistic issues
-e663		// Suspicious array to pointer conversion
//-e574		// Signed-unsigned mix with relational
-e641		// Converting enum '...' to int
-e716		// while(1) ...
-e726		// Extraneous comma ignored
-e728		// Symbol ... not explicitly initialized
-e737		// Loss of sign in promotion from int to unsigned int
-e763		// Redundant declaration for symbol '...' previously declared
-e717		// do ... while(0);
-e777		// Testing floats for equality
-e785		// Too few initializers for aggregate
-e786		// String concatenation within initializer

-e788		// enum constant '___' not used within defaulted switch

-esym(818, argv)	// Pointer parameter '...' could be declared as pointing to const

-e850		// loop variable modified in loop

/*
 * va_list's are opaque for a reason, but we pretend to FlexeLint that it
 * is just a void*, so it proposes constification, which is not generally OK,
 * for instance on register-spilling architectures.
 * XXX: Maybe 'ap' is a badly chosen conventional name here...
 */
-esym(818, ap)		// Pointer parameter '...' could be declared as pointing to const

-efunc(789, main)	// Assigning address of auto variable '...' to static

// +e958		// padding

///////////////////////////////////////////////////////////////////////
// System/Posix/Iso-C library related

-emacro(747, isnan)     // significant coercion
-emacro(506, isinf)	// Constant value Boolean
-emacro(866, isinf)	// Unusual use of '?' in argument to sizeof
-emacro(736, isinf)	// Loss of precision

// ignore retval
-esym(534, printf)
-esym(534, fprintf)
-esym(534, vfprintf)
-esym(534, sprintf)
-esym(534, fputc)

-esym(534, memset)
-esym(534, memcpy)
-esym(534, memmove)

-esym(534, strcat)
-esym(534, strcpy)
-esym(534, strncpy)

-esym(534, sleep)
-esym(534, usleep)


///////////////////////////////////////////////////////////////////////
// Vmod/vmodtool.py

//-esym(14, vmod_enum_*)		// Symbol '___' previously defined (___)
//-esym(759, vmod_enum_*)		// header declaration for symbol '___' defined at (___)
//-esym(765, vmod_enum_*)		// external '___' (___) could be made static

///////////////////////////////////////////////////////////////////////
// <vut.h>

-sem(VUT_Error, r_no)

///////////////////////////////////////////////////////////////////////
// <vas.h>

-sem(VAS_Fail, r_no)		// does not return
-emacro(506, assert)		// constant value boolean
-emacro(827, assert)		// loop not reachable
-emacro(774, assert)		// boolean always true
-emacro(731, assert)		// boolean arg to eq/non-eq
-emacro(731, xxxassert)		// arg to eq/non-eq
-emacro(527, WRONG)		// unreachable code
-emacro(774, VALID_OBJ)		// boolean always true
-emacro(506, VALID_OBJ)		// Constant value Boolean

-emacro(506, v_static_assert)	// Constant value Boolean
-esym(751, __vassert_*)		// local typedef '___' (___) not referenced

///////////////////////////////////////////////////////////////////////
// Places where we use x<<0 for reasons of symmetry

-emacro(835, VCT_SP)		// A zero has been given as ___ argument to operator '___'
-emacro(835, VSL_COPT_TAIL)	// A zero has been given as ___ argument to operator '___'
-emacro(835, SLT_F_UNUSED)	// A zero has been given as ___ argument to operator '___'
-emacro(835, ARGV_COMMENT)	// A zero has been given as ___ argument to operator '___'
-emacro(835, F_SEEN_ixIX)	// A zero has been given as ___ argument to operator '___'
-emacro(835, VEX_OPT_CASELESS)	// A zero has been given as ___ argument to operator '___'

///////////////////////////////////////////////////////////////////////
// <vsb.h>

-esym(759, VSB_*)		// header decl could be moved
-esym(765, VSB_*)		// extern could be made static
-esym(714, VSB_*)		// symb not ref
-sem(VSB_new, @p == (1p ? 1p : malloc(1)))
-sem(VSB_delete, custodial(1))

// ignore retval
-esym(534, VSB_cat)
-esym(534, VSB_bcat)
-esym(534, VSB_putc)
-esym(534, VSB_printf)
-esym(534, VSB_vprintf)

///////////////////////////////////////////////////////////////////////
// <vte.h>

// ignore retval
-esym(534, VTE_cat)
-esym(534, VTE_putc)
-esym(534, VTE_printf)

///////////////////////////////////////////////////////////////////////
// <vtree.h>

// -emacro(801, VRBT_*)		// goto considered bad
-emacro(527, VRBT_*)		// unreachable code
-emacro(740, VRBT_*)		// unusual pointer cast
-emacro(438, VRBT_*)		// last value assigned not used
-emacro(613, VRBT_*)	// Possible use of null pointer 'child' in left argument to
-emacro(838, VRBT_*)	// Previously assigned value to variable 'child' has not been used
-emacro(50, VRBT_GENERATE_*) // Attempted to take the address of a non-lvalue
-emacro(506, VRBT_GENERATE_*) // Constant value Boolean
-emacro(845, VRBT_GENERATE_*) // The left argument to operator '&&' is certain to be 0
-emacro(774, VRBT_GENERATE_*) // Boolean within 'if' always evaluates to False
-esym(534, *_VRBT_REMOVE)	// ignore retval
-esym(534, *_VRBT_INSERT)	// ignore retval

///////////////////////////////////////////////////////////////////////
// <vqueue.h>

-esym(755, VLIST_*)	// Global macro not ref.
-esym(755, VSLIST_*)
-esym(755, VSTAILQ_*)
-esym(755, VTAILQ_*)

// 506 = constant value boolean
-emacro(506, VTAILQ_FOREACH_REVERSE_SAFE)
-emacro(506, VTAILQ_FOREACH_SAFE)
-emacro(506, VSTAILQ_FOREACH_SAFE) // constant value boolean

// 826 = Suspicious pointer-to-pointer conversion (area to o small)
-emacro((826), VTAILQ_LAST)
-emacro((826), VTAILQ_PREV)

-emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types)
-emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types)

-esym(754, "*::vtqh_first")	// local struct member '...' not referenced

///////////////////////////////////////////////////////////////////////
// <vdef.h>
-emacro(527, NEEDLESS)	// unreachable code
-emacro(160, _vtake, __containerof)	// The sequence '( {' is non standard
+rw( __typeof__ )

///////////////////////////////////////////////////////////////////////
// <vrt.h>
-emacro(446, TOSTRAND, TOSTRANDS)	// side effect in initializer

///////////////////////////////////////////////////////////////////////
// <libvinylapi>

-esym(765, vsl_vbm_bitclr)
-esym(759, vsl_vbm_bitclr)
-esym(765, vsl_vbm_bitset)
-esym(759, vsl_vbm_bitset)
-esym(765, vsm_diag)
-esym(759, vsm_diag)

///////////////////////////////////////////////////////////////////////
// "miniobj.h"

-emacro(774, REPLACE)
// Flexelint does not understand offsetof(typeof(*ptr))
-emacro(10, SIZEOF_FLEX_OBJ)
-emacro(40, SIZEOF_FLEX_OBJ)


// It is ok to default after handling a few select SLT_* tags
-esym(788, VSL_tag_e::SLT_*)	//  enum constant '...' not used within defaulted switch

-esym(785,VSL_tags)				// Sparse array

///////////////////////////////////////////////////////////////////////
// readline etc.

-esym(534, add_history)

///////////////////////////////////////////////////////////////////////
// -lcurses
-esym(534, beep)
-esym(534, curs_set)
-esym(534, delwin)
-esym(534, doupdate)
-esym(534, endwin)
-esym(534, initscr)
-esym(534, intrflush)
-esym(534, keypad)
-esym(534, mvprintw)
-esym(534, waddnstr)
-esym(534, mvwprintw)
-esym(534, nodelay)
-esym(534, noecho)
-esym(534, nonl)
-esym(534, raw)
-esym(534, waddch)
-esym(534, wattr_off)
-esym(534, wattr_on)
-esym(534, wbkgd)
-esym(534, werase)
-esym(534, wmove)
-esym(534, wnoutrefresh)
-esym(534, wprintw)
-esym(534, wredrawln)
-esym(534, wrefresh)

///////////////////////////////////////////////////////////////////////
// vmod_debug, put here because it is used twice (vinyld2 and separate)
-esym(768, arg_xyzzy_debug_argtest::*)

///////////////////////////////////////////////////////////////////////
// Noise reduction, review periodically

-e459	// unlocked access from func-ptr
-e679	// Suspicious Truncation in arithmetic expression combining with pointer
-e712	// Loss of precision (___) (___ to ___)
-e713	// Loss of precision (___) (___ to ___)
-e732	// Loss of sign (___) (___ to ___)
-e734	// Loss of precision (___) (___ bits to ___ bits)
-e747	// Significant prototype coercion (___) ___ to ___
