Skip to content

[clang-tidy] overflow builtins always write their output operand #136812

Open
@resistor

Description

@resistor

Consider the following code:

int test(int elementSize, int elementCount)
{
	int bufferSize;
	int allocSize;
	bool overflow = __builtin_mul_overflow(elementCount, elementSize, &bufferSize);
	overflow |= __builtin_add_overflow(4, bufferSize, &allocSize);
	if (overflow)
		return -1;
	return allocSize;
}

clang-tidy-20 produces the following false-positive warning:

foo.cpp:6:14: warning: 2nd function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
    6 |         overflow |= __builtin_add_overflow(4, bufferSize, &allocSize);

This seems to be because it does not understand that the prior call to __builtin_mul_overflow will always write to bufferSize.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions