[clang] [Clang] Avoid crash with wide string CPU builtin argument (PR #245515)

Bhavya Gautam via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 28 20:37:27 PST 2026


================
@@ -672,7 +675,10 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
 
 Value *CodeGenFunction::EmitX86CpuSupports(const CallExpr *E) {
   const Expr *FeatureExpr = E->getArg(0)->IgnoreParenCasts();
-  StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString();
+  const StringLiteral *Literal = dyn_cast<StringLiteral>(FeatureExpr);
----------------
gautam899 wrote:

Got it. 
My current approach is to introduce a dedicated diagnostics in `DiagnosticSemaKinds.td` for invalid arguments to `__builtin_cpu-*`. If the argument validation fails in SemaChecking.cpp, I would emit this diagnostic and return.
Would that be the right approach? or would you prefer handling this through existing argument type-checking diagnostics?

https://github.com/llvm/llvm-project/pull/245515


More information about the cfe-commits mailing list