Skip to content

Unknown references and pointers related bad codegen #141114

@shafik

Description

@shafik

This semi-reduced code from: #95474 (comment)

struct MyStruct {
    double m0{-9999.0};
    int m1{-12345};
};

constexpr MyStruct default_val;

auto compute_area(double l, const MyStruct &val = default_val) -> double {
    if (val.m1 == 1)
      return 2.0;
    return 0;
}


#include <cassert>


auto main() -> int {
    MyStruct in_val{.m0 = 2.0, .m1 = 1};
    double val = compute_area(1.0, in_val);
    assert(val == 2.0);
}

crashes at runtime, it looks like due to VD->getAnyInitializer(VD) pulling in the default value.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"miscompilationneeds-reductionLarge reproducer that should be reduced into a simpler form

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions