This revision was automatically updated to reflect the committed changes. Closed by commit rGd260a10d98df: [clang] Fix crash during template sema checking (authored by gchatelet).
Changed prior to commit: https://reviews.llvm.org/D76504?vs=251780&id=251837#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D76504/new/ https://reviews.llvm.org/D76504 Files: clang/lib/Sema/SemaChecking.cpp clang/test/Sema/builtins-memcpy-inline.c clang/test/Sema/builtins-memcpy-inline.cpp Index: clang/test/Sema/builtins-memcpy-inline.cpp =================================================================== --- clang/test/Sema/builtins-memcpy-inline.cpp +++ clang/test/Sema/builtins-memcpy-inline.cpp @@ -30,3 +30,9 @@ void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned size) { __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to '__builtin_memcpy_inline' must be a constant integer}} } + +template <unsigned size> +void test_memcpy_inline_template(void *dst, const void *src) { + // we do not try to evaluate size in non intantiated templates. + __builtin_memcpy_inline(dst, src, size); +} Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -1649,11 +1649,16 @@ case Builtin::BI__builtin_nontemporal_store: return SemaBuiltinNontemporalOverloaded(TheCallResult); case Builtin::BI__builtin_memcpy_inline: { - // __builtin_memcpy_inline size argument is a constant by definition. - if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue()) + clang::Expr *SizeOp = TheCall->getArg(2); + // We warn about copying to or from `nullptr` pointers when `size` is + // greater than 0. When `size` is value dependent we cannot evaluate its + // value so we bail out. + if (SizeOp->isValueDependent()) break; - CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc()); - CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc()); + if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) { + CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc()); + CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc()); + } break; } #define BUILTIN(ID, TYPE, ATTRS)
Index: clang/test/Sema/builtins-memcpy-inline.cpp =================================================================== --- clang/test/Sema/builtins-memcpy-inline.cpp +++ clang/test/Sema/builtins-memcpy-inline.cpp @@ -30,3 +30,9 @@ void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned size) { __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to '__builtin_memcpy_inline' must be a constant integer}} } + +template <unsigned size> +void test_memcpy_inline_template(void *dst, const void *src) { + // we do not try to evaluate size in non intantiated templates. + __builtin_memcpy_inline(dst, src, size); +} Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -1649,11 +1649,16 @@ case Builtin::BI__builtin_nontemporal_store: return SemaBuiltinNontemporalOverloaded(TheCallResult); case Builtin::BI__builtin_memcpy_inline: { - // __builtin_memcpy_inline size argument is a constant by definition. - if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue()) + clang::Expr *SizeOp = TheCall->getArg(2); + // We warn about copying to or from `nullptr` pointers when `size` is + // greater than 0. When `size` is value dependent we cannot evaluate its + // value so we bail out. + if (SizeOp->isValueDependent()) break; - CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc()); - CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc()); + if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) { + CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc()); + CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc()); + } break; } #define BUILTIN(ID, TYPE, ATTRS)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits