appleseedlab / maki

A tool for analyzing syntactic and semantic properties of C Preprocessor macros in C programs
8 stars 3 forks source link

Fix clang assertion failure in getting type of sizeof/cast expression #40

Closed SilverMight closed 2 months ago

SilverMight commented 2 months ago

In the definition of DoesSubexpressionExpandedFromBodyHaveTypeDefinedAfterMacro, getArgumentType is called after a statement is cast to UnaryExprOrTypeTraitExpr. If the type of the statement is an expr and not an argument, this will trigger an assertion and crash clang, as seen when analyzing certain parts of bash:

clang-17: /usr/lib/llvm-17/include/clang/AST/Expr.h:2626: clang::TypeSourceInfo* clang::UnaryExprOrTypeTraitExpr::getArgumentTypeInfo() const: Assertion `isArgumentType() && "calling getArgumentType() when arg is expr"' failed.

Calling UnaryExprOrTypeTraitExpr::getTypeOfArgument instead handles this difference and calls the appropriate function, and fixes this crash.

  /// Gets the argument type, or the type of the argument expression, whichever
  /// is appropriate.
  QualType getTypeOfArgument() const {
    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
  }