-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Description
Description
The ComputeImpl method in INT8Quantizer class has undefined behavior when the L2SQR branch is used. The function may reach the end without a return statement, which is undefined behavior for a non-void function.
Background
During code review of the quantization module, it was discovered that the ComputeImpl method in src/quantization/int8_quantizer.cpp has a code path that could lead to undefined behavior:
- The IP and COSINE branches use
if constexpr, which allows compile-time branch elimination - The L2SQR branch uses a regular
if(withoutconstexpr), so the compiler cannot eliminate the fall-through path - If control flow doesn't enter any branch (theoretically shouldn't happen, but the compiler can't prove it), the function ends without a return statement
- Missing return in a non-void function is undefined behavior, and the compiler may generate unpredictable code
Requirements
- Add
static_assertto ensure only supported metric types are used - Change
else iftoelse if constexprfor L2SQR branch - Ensure all branches use
if constexprfor compile-time branch elimination - Eliminate undefined behavior
Technical Details
File Modified: src/quantization/int8_quantizer.cpp
Changes Made:
- Added
static_assertat the beginning ofComputeImplfunction to validate metric type - Changed
else if (metric == MetricType::METRIC_TYPE_L2SQR)toelse if constexpr (metric == MetricType::METRIC_TYPE_L2SQR)
Acceptance Criteria
- Code compiles without warnings
- All existing tests pass
- No undefined behavior in the function
- Compile-time branch elimination works correctly for all metric types
Related
- Original task file:
agent-hive/tasks/2026-03-18-修复-int8-quantizer-computeimpl-缺少-return.md - Reference implementation:
ComputeDistImplfunction in the same file (lines 156-186)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels