Skip to content

[BUG] GCC optimizes away the write with benchmark::DoNotOptimize #2282

Description

@SaiCharanMarrivada

GCC16.1 optimizes away the write when we use benchmark::DoNotOptimize.

Minimal reproducible example

void f() {
    int *a = new int[1 << 16];
    for (int i = 0; i < 1 << 16; i++) {
        benchmark::DoNotOptimize(a[i] = 10); // this is optimized away by the compiler
    }
    delete[] a;
}

Compiler explorer(CE) link: https://godbolt.org/z/j538536ss. The CE link contains a possible fix for the issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions