Skip to content

Clang does not recognize hand-written buffer aliasing checks #146401

Open
@davidben

Description

@davidben

Clang (and GCC) don't seem to recognize the __fh_overlap macro in https://godbolt.org/z/EqjKe716r as a buffer aliasing check.

The sample was adapted from https://github.com/jvoisin/fortify-headers/blob/master/include/string.h, which is reportedly used in Musl-based Linux distributions like Alpine.

In this case, since r was just allocated, the compiler should be able to reason that r cannot overlap with a and delete the __fh_overlap check. It's also important to be able to optimize this because memcpy is the usual pattern to load memory without tripping strict aliasing issues.

CC @andres-erbsen

Metadata

Metadata

Assignees

No one assigned

    Labels

    TBAAType-Based Alias Analysis / Strict AliasingclangClang issues not falling into any other categorymissed-optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions