[spirv] Fix failure caused by multiplying size() and int (#3379)

The code `int foo; .. size(float) * foo` causes failure because
`getElementSpirvBitwidth()` in AstTypeProbe.cpp does not handle the type
of `sizeof()` which is the "unsigned long" type. This commit handles it.

Fixes #2814
This commit is contained in:
Jaebaek Seo 2021-01-22 16:54:13 -05:00 коммит произвёл GitHub
Родитель 7c9e487afd
Коммит a3c52dbbbc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -441,6 +441,8 @@ uint32_t getElementSpirvBitwidth(const ASTContext &astContext, QualType type,
case BuiltinType::Int8_4Packed:
case BuiltinType::UInt8_4Packed:
case BuiltinType::Float:
case BuiltinType::Long:
case BuiltinType::ULong:
return 32;
case BuiltinType::Double:
case BuiltinType::LongLong:

Просмотреть файл

@ -45,4 +45,10 @@ void main() {
struct {} _; // Zero-sized field.
} complexStruct;
buf.Append(sizeof(complexStruct));
// CHECK: [[foo:%\d+]] = OpLoad %int %foo
// CHECK-NEXT: [[ui_foo:%\d+]] = OpBitcast %uint [[foo]]
// CHECK-NEXT: OpIMul %uint %uint_4 [[ui_foo]]
int foo;
buf.Append(sizeof(float) * foo);
}