Skip to content

[Clang FE] Possible logic issue in TransformTypos::TransformDesignatedInitExpr #126113

@d367wang

Description

@d367wang

When running the tree-visitor TransformTypos on a DesignatedInitExpr node, it first tries to transform its initializer

// transform the initializer value
  ExprResult Init = getDerived().TransformExpr(E->getInit());

and later on decides whether the AST changes by

ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);

at

ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);

The logic in Init.get() != E->getArrayIndex(D) seems not correct as the initializer and the index of the designator are being compared, which is likely to always be true. In contrast, later in the same function

Init.get() == E->getInit() &&

The old initializer and the initializer after transform are compared.

Ran debugger on clang compiling a designator example

const char *str[] = {
    [some_typo] = "0"
};

and stepped in to the line, Init.get() is a StringLiteral and E->getArrayIndex(D) is a TypoExpr.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"good first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions