cgen: add WUFFS_BASE__GENERATED_C_CODE macro

This disables UBSan's "unsigned-integer-overflow" runtime checks.

Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59966
This commit is contained in:
Nigel Tao committed 2023-06-20 17:04:35 +10:00
1 parent 6eb92544bd
commit e7df7cafac
3 files changed
+638

No files matched your search

+20
View File
@@ -284,6 +284,26 @@ wuffs_base__cpu_arch__have_x86_sse42() {
#define WUFFS_BASE__WARN_UNUSED_RESULT
#endif
// Clang's "-fsanitize=integer" checks for "unsigned-integer-overflow" even
// though, for *unsigned* integers, it is *not* undefined behavior. The check
// is still made because unsigned integer overflow "is often unintentional".
// https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
//
// However, for Wuffs' generated C code, unsigned overflow is intentional. The
// programmer has to use "~mod+" instead of a plain "+" operator in Wuffs code.
// Further runtime checks for unsigned integer overflow can add performance
// overhead (fuzzers can then time out) and can raise false negatives, without
// generating much benefits. We disable the "unsigned-integer-overflow" check.
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer)
#define WUFFS_BASE__GENERATED_C_CODE \
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
#endif
#if !defined(WUFFS_BASE__GENERATED_C_CODE)
#define WUFFS_BASE__GENERATED_C_CODE
#endif
// --------
// Options (bitwise or'ed together) for wuffs_foo__bar__initialize functions.
+2
View File
@@ -90,6 +90,7 @@ const (
func (g *gen) writeFuncSignature(b *buffer, n *a.Func, wfs uint32) error {
switch wfs {
case wfsCDecl:
b.writes("WUFFS_BASE__GENERATED_C_CODE\n")
if n.Public() {
b.writes("WUFFS_BASE__MAYBE_STATIC ")
} else {
@@ -97,6 +98,7 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func, wfs uint32) error {
}
case wfsCDeclChoosy:
b.writes("WUFFS_BASE__GENERATED_C_CODE\n")
b.writes("static ")
case wfsCppDecl: