Skip to content

[clang/c++] Very strange/bad optimizer behavior. #89699

Open
@no-more-secrets

Description

@no-more-secrets

Problem demo: https://godbolt.org/z/zfMohEMj7

The "good" variant produces perfectly optimized code, while the nearly-identical "bad" variant produces a giant explosion of seemingly unoptimized code.

static int len( char const* input ) {
  return std::string( input ).size();
}

int test() {
  return
    #ifdef GOOD
      len( "h" ) + len( "h" );
    #else /*BAD*/
      len( "h" ) + len( "" );
    #endif
}

This (regression?) happened between Clang versions 13 and 14: https://godbolt.org/z/brhYEK4Eh

The problem does not exist in gcc: https://godbolt.org/z/Ed6z6j61a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions