FAILURE MAP
← Case archive

FA-9261 / Build systems / Open access

Compiler option precedence: Optimization options survive twice · case 01

Optimization options survive twice.

Verified by executionVariant 1 · 6 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The implementation substitutes x == '-O' for x.startswith('-O'), so optimization options survive twice.

VERIFIED REPAIR

Recognize every optimization option by its prefix.

Unsuccessful approach: The attempted repair substitutes x.startswith('-O0'). Fixture 2 still yields ['-Ifoo', '-Ifoo', '-O0', '-g'] instead of ['-Ifoo', '-Ifoo', '-O2', '-g'].

Case contract

Append defaults, replace optimization options by the last requested optimization, preserve repeated include options, remove explicitly disabled warnings, and append mandatory flags exactly once.

Why this case matters

An offline model of compiler option precedence, suitable for testing build and release tooling without external services.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(defaults, requested, disabled, mandatory):
    flags = list(defaults) + list(requested)
    opts = [x for x in flags if x == '-O']
    flags = [x for x in flags if not x.startswith('-O')]
    flags = [x for x in flags if x not in disabled]
    if opts: flags.append(opts[-1])
    for flag in mandatory:
        if flag not in flags: flags.append(flag)
    return flags
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1', solve([], [], [], []), [])
check('fixture 2', solve(['-O0', '-Wall'], ['-O2', '-Ifoo', '-Ifoo'], ['-Wall'], ['-g']), ['-Ifoo', '-Ifoo', '-O2', '-g'])
check('fixture 3', solve(['-O1'], ['-O3'], [], []), ['-O3'])
check('fixture 4', solve(['-g'], [], [], ['-g']), ['-g'])
check('fixture 5', solve(['-Wa', '-Wb'], [], ['-Wa'], []), ['-Wb'])
check('fixture 6', solve([], ['-Ifoo', '-Ibar'], [], ['-g', '-g']), ['-Ifoo', '-Ibar', '-g'])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
fixture 1[][]Passed
fixture 2['-Ifoo', '-Ifoo', '-g']['-Ifoo', '-Ifoo', '-O2', '-g']Failed
fixture 3[]['-O3']Failed
fixture 4['-g']['-g']Passed
fixture 5['-Wb']['-Wb']Passed
fixture 6['-Ifoo', '-Ibar', '-g']['-Ifoo', '-Ibar', '-g']Passed

SHA-256 / 6ed0f0265be11ce1c5e3251af21943dbe659ba61aa71acb5b2ec6973d91a5210

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(defaults, requested, disabled, mandatory):
    flags = list(defaults) + list(requested)
    opts = [x for x in flags if x.startswith('-O0')]
    flags = [x for x in flags if not x.startswith('-O')]
    flags = [x for x in flags if x not in disabled]
    if opts: flags.append(opts[-1])
    for flag in mandatory:
        if flag not in flags: flags.append(flag)
    return flags
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1', solve([], [], [], []), [])
check('fixture 2', solve(['-O0', '-Wall'], ['-O2', '-Ifoo', '-Ifoo'], ['-Wall'], ['-g']), ['-Ifoo', '-Ifoo', '-O2', '-g'])
check('fixture 3', solve(['-O1'], ['-O3'], [], []), ['-O3'])
check('fixture 4', solve(['-g'], [], [], ['-g']), ['-g'])
check('fixture 5', solve(['-Wa', '-Wb'], [], ['-Wa'], []), ['-Wb'])
check('fixture 6', solve([], ['-Ifoo', '-Ibar'], [], ['-g', '-g']), ['-Ifoo', '-Ibar', '-g'])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
fixture 1[][]Passed
fixture 2['-Ifoo', '-Ifoo', '-O0', '-g']['-Ifoo', '-Ifoo', '-O2', '-g']Failed
fixture 3[]['-O3']Failed
fixture 4['-g']['-g']Passed
fixture 5['-Wb']['-Wb']Passed
fixture 6['-Ifoo', '-Ibar', '-g']['-Ifoo', '-Ibar', '-g']Passed

SHA-256 / 42b805441cf450863017cad50b7bd038216be05fe0bdf768baa9a72c00f04f40

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(defaults, requested, disabled, mandatory):
    flags = list(defaults) + list(requested)
    opts = [x for x in flags if x.startswith('-O')]
    flags = [x for x in flags if not x.startswith('-O')]
    flags = [x for x in flags if x not in disabled]
    if opts: flags.append(opts[-1])
    for flag in mandatory:
        if flag not in flags: flags.append(flag)
    return flags
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1', solve([], [], [], []), [])
check('fixture 2', solve(['-O0', '-Wall'], ['-O2', '-Ifoo', '-Ifoo'], ['-Wall'], ['-g']), ['-Ifoo', '-Ifoo', '-O2', '-g'])
check('fixture 3', solve(['-O1'], ['-O3'], [], []), ['-O3'])
check('fixture 4', solve(['-g'], [], [], ['-g']), ['-g'])
check('fixture 5', solve(['-Wa', '-Wb'], [], ['-Wa'], []), ['-Wb'])
check('fixture 6', solve([], ['-Ifoo', '-Ibar'], [], ['-g', '-g']), ['-Ifoo', '-Ibar', '-g'])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
fixture 1[][]Passed
fixture 2['-Ifoo', '-Ifoo', '-O2', '-g']['-Ifoo', '-Ifoo', '-O2', '-g']Passed
fixture 3['-O3']['-O3']Passed
fixture 4['-g']['-g']Passed
fixture 5['-Wb']['-Wb']Passed
fixture 6['-Ifoo', '-Ibar', '-g']['-Ifoo', '-Ibar', '-g']Passed

SHA-256 / b4bb251e00777e051e560851f671826ee06cfaf8bb741bcc364a5aa6245f0297

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:38:28.484986+00:00.

Case digest / c362f46d14de7770f9fb58dbb434b581c53a5fa31350a786deab66ef40f9718a