https://github.com/huseyin-donmez created https://github.com/llvm/llvm-project/pull/205017
fix for ICE in `Sema::CheckAbsoluteValueFunction` problem: when a 1-element vector is passed to a `abs` function, it implicitly casts to its scalar type, passing the initial type checks. However, `QualType ArgType = Call->getArg(0)->IgnoreParenImpCasts()->getType();` strips this cast, leaving the raw vector type, which is then passed to getAbsoluteValueKind() triggering an `llvm_unreachable`, since it's expecting only integer, enum, real floating or any complex type. solution: early return for invalid types before `getAbsoluteValueKind()`. A regression test has been added to ensure the compiler no longer crashes. Fixes: #204777 From d86158ea51618acd0a6c684cf2b1e0bef3b216b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20D=C3=B6nmez?= <[email protected]> Date: Mon, 22 Jun 2026 02:04:21 +0200 Subject: [PATCH] [Sema] Fix ICE when passing invalid types to abs and cause unreachable code crash --- clang/lib/Sema/SemaChecking.cpp | 6 ++++++ clang/test/Sema/builtin-abs-invalid.c | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 clang/test/Sema/builtin-abs-invalid.c diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ec4a9037f5c23..294729b33a6ec 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -10527,6 +10527,12 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, if (IsStdAbs) return; + // Prevent reaching unreachable code in getAbsoluteValueKind for unsupported + // types. + if (!ArgType->isIntegralOrEnumerationType() && + !ArgType->isRealFloatingType() && !ArgType->isAnyComplexType()) + return; + AbsoluteValueKind ArgValueKind = getAbsoluteValueKind(ArgType); AbsoluteValueKind ParamValueKind = getAbsoluteValueKind(ParamType); diff --git a/clang/test/Sema/builtin-abs-invalid.c b/clang/test/Sema/builtin-abs-invalid.c new file mode 100644 index 0000000000000..9ec6c0edc491a --- /dev/null +++ b/clang/test/Sema/builtin-abs-invalid.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s +// expected-no-diagnostics + +int abs(int); + +typedef int int1 __attribute__((__vector_size__(4))); + +void test_vector_abs(int1 x) { + (void)abs(x); +} \ No newline at end of file _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
