Skip to content

Commit cdad183

Browse files
authored
[clang] Fix #embed "fast path" (#121479)
When a single #embed directive is used to initialize a char array, the case is optimized via swap of EmbedExpr to underlying StringLiteral, resulting in better performance in AST consumers. While browsing through the code, I realized that 7122b70 which changed type of EmbedExpr made the "fast path" unreachable. This patch fixes this unfortunate situation.
1 parent ad192f9 commit cdad183

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,13 +2030,8 @@ canInitializeArrayWithEmbedDataString(ArrayRef<Expr *> ExprList,
20302030

20312031
if (InitType->isArrayType()) {
20322032
const ArrayType *InitArrayType = InitType->getAsArrayTypeUnsafe();
2033-
QualType InitElementTy = InitArrayType->getElementType();
2034-
QualType EmbedExprElementTy = EE->getDataStringLiteral()->getType();
2035-
const bool TypesMatch =
2036-
Context.typesAreCompatible(InitElementTy, EmbedExprElementTy) ||
2037-
(InitElementTy->isCharType() && EmbedExprElementTy->isCharType());
2038-
if (TypesMatch)
2039-
return true;
2033+
StringLiteral *SL = EE->getDataStringLiteral();
2034+
return IsStringInit(SL, InitArrayType, Context) == SIF_None;
20402035
}
20412036
return false;
20422037
}

clang/test/Analysis/embed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ int main() {
88
#embed "embed.c"
99
};
1010
clang_analyzer_dump_ptr(SelfBytes); // expected-warning {{&Element{SelfBytes,0 S64b,unsigned char}}}
11-
clang_analyzer_dump(SelfBytes[0]); // expected-warning {{Unknown}} FIXME: This should be the `/` character.
11+
clang_analyzer_dump(SelfBytes[0]); // expected-warning {{47 U8b}}
1212
}

0 commit comments

Comments
 (0)