Commit Graph

2 Commits

Author SHA1 Message Date
xgopilot
1ec0d09e95 test: Fix float-to-int conversion tests to document undefined behavior
- Changed float-to-int overflow tests to use t.Logf() instead of assertions
- Go's spec defines out-of-range float-to-int conversions as undefined behavior
- All tests now pass with both standard Go and llgo compiler
- Tests properly document actual behavior without asserting specific values

Related to #961

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: cpunion <cpunion@users.noreply.github.com>
2025-10-22 04:01:16 +00:00
xgopilot
1ba9618188 Add unit tests for type conversion and overflow issues (issue #961)
This commit adds comprehensive unit tests in test/go/ directory to validate
type conversion behavior and identify bugs in LLGo's BinOp code generation.

Tests added:
1. test/go/type_conv_test.go:
   - TestIntegerOverflow: Tests integer overflow wrapping behavior
   - TestFloatToIntConversion: Tests float-to-int conversions with saturation
   - TestUint32ToFloatToInt32: Specific test for issue #961 bug case
   - TestFloatSpecialValues: Tests Inf/NaN handling
   - TestSignedUnsignedConversions: Tests signed/unsigned conversions
   - TestSignExtensionVsZeroExtension: Tests type extension behavior
   - TestIntToFloatPrecisionLoss: Tests precision loss in conversions

2. test/go/untyped_const_test.go:
   - TestUntypedConstantWithTypedVariable: Tests untyped constants with typed vars
   - TestUntypedConstantArithmetic: Tests untyped constant operations
   - TestUntypedConstantExpression: Tests constant expression evaluation
   - TestMixedUntypedTypedExpressions: Tests mixed expressions
   - TestUntypedBool/String/Rune/ZeroValues: Tests untyped constants

Test results with standard Go:
- Integer overflow tests: PASS (documents correct Go wrapping behavior)
- Untyped constant tests: PASS (validates proper type inference)
- Float-to-int tests: Some FAIL (documents that Go has undefined behavior
  for out-of-range conversions, not saturation as initially expected)

These tests will help identify where LLGo differs from standard Go behavior.

Related: #961

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: cpunion <cpunion@users.noreply.github.com>
2025-10-22 02:34:41 +00:00