StringLiteral is used as internal data of EmbedExpr and we directly use it as an initializer if a single EmbedExpr appears in the initializer list of a char array. It is fast and convenient, but it is causing problems when string literal character values are checked because #embed data values are within a range [0-2^(char width)] but ordinary StringLiteral is of maybe signed char type. This PR introduces new kind of StringLiteral to hold binary data coming from an embedded resource to mitigate these problems. The new kind of StringLiteral is not assumed to have signed char type. The new kind of StringLiteral also helps to prevent crashes when trying to find StringLiteral token locations since these simply do not exist for binary data. Fixes https://github.com/llvm/llvm-project/issues/119256
22 lines
652 B
C
22 lines
652 B
C
// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify -std=c23
|
|
|
|
static constexpr unsigned char data[] = {
|
|
#embed "big_char.txt"
|
|
};
|
|
|
|
static constexpr char data1[] = {
|
|
#embed "big_char.txt" // expected-error {{constexpr initializer evaluates to 255 which is not exactly representable in type 'const char'}}
|
|
};
|
|
|
|
static constexpr int data2[] = {
|
|
#embed "big_char.txt"
|
|
};
|
|
|
|
static constexpr unsigned data3[] = {
|
|
#embed "big_char.txt" suffix(, -1) // expected-error {{constexpr initializer evaluates to -1 which is not exactly representable in type 'const unsigned int'}}
|
|
};
|
|
|
|
static constexpr int data4[] = {
|
|
#embed "big_char.txt" suffix(, -1)
|
|
};
|