Skip to content

[CodeGen] It's not rational to promote the local variable to unnamed global variable in CodeGen. #158175

@hstk30-hw

Description

@hstk30-hw

https://godbolt.org/z/vj687zjTM

For code

typedef struct {
    const char *strType;
    int dataType;
} DataTypePairT;

void init(const DataTypePairT * am);

void test() {
    DataTypePairT bitDataType[] = {
        {"uint16", 1},
        {"uint32", 2},
        {"uint64", 3},
        {"uint8", 4}
    };

    init(bitDataType);
}

LLVM will promote the local varibal bitDataType to an unnamed global variable. It's counterintuitive.

Address CodeGenModule::createUnnamedGlobalFrom(const VarDecl &D,
llvm::Constant *Constant,
CharUnits Align) {

It will put the data to '.data.rel.ro' section.

Maybe we can do this as an optimization, and default on it. Now we implement it in CodeGen seems not rational.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions