[clang][CGStmt] fix crash on invalid asm statement
authorTong Zhang <ztong0001@gmail.com>
Wed, 2 Mar 2022 19:18:54 +0000 (11:18 -0800)
committerFangrui Song <i@maskray.me>
Wed, 2 Mar 2022 19:18:55 +0000 (11:18 -0800)
commitf76d3b800f7341882ea93db47cc8f28d94e74f1c
tree747aa2fa9665e37dbe5b9a48b76cf188af02d165
parentdaba82362228b4aa460c26079c028ebf832066fd
[clang][CGStmt] fix crash on invalid asm statement

Clang is crashing on the following statement

  char var[9];
  __asm__ ("" : "=r" (var) : "0" (var));

This is similar to existing test: crbug_999160_regtest

The issue happens when EmitAsmStmt is trying to convert input to match
output type length. However, that is not guaranteed to be successful all the
time and if the statement itself is invalid like having an array type in
the example, we should give a regular error message here instead of
using assert().

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D120596
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/X86/x86_64-PR42672.c