llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> This pretty hard to produce in C++ but easy in C. Fixes #<!-- -->171609 --- Full diff: https://github.com/llvm/llvm-project/pull/174184.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+13-2) - (modified) clang/test/AST/ByteCode/builtins.c (+1) ``````````diff diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 57d5f0ae6eed3..65101174247d1 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -64,6 +64,18 @@ static APSInt popToAPSInt(InterpState &S, QualType T) { return popToAPSInt(S.Stk, *S.getContext().classify(T)); } +/// Check for common reasons a pointer can't be read from, which +/// are usually not diagnosed in a builtin function. +static bool isReadable(const Pointer &P) { + if (P.isDummy()) + return false; + if (!P.isBlockPointer()) + return false; + if (!P.isLive()) + return false; + return true; +} + /// Pushes \p Val on the stack as the type given by \p QT. static void pushInteger(InterpState &S, const APSInt &Val, QualType QT) { assert(QT->isSignedIntegerOrEnumerationType() || @@ -1794,8 +1806,7 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC, return false; } - // Can't read from dummy pointers. - if (DestPtr.isDummy() || SrcPtr.isDummy()) + if (!isReadable(DestPtr) || !isReadable(SrcPtr)) return false; if (DestPtr.getType()->isIncompleteType()) { diff --git a/clang/test/AST/ByteCode/builtins.c b/clang/test/AST/ByteCode/builtins.c index a51260cd3431f..5be5455ab8813 100644 --- a/clang/test/AST/ByteCode/builtins.c +++ b/clang/test/AST/ByteCode/builtins.c @@ -17,3 +17,4 @@ int structStrlen(void) { return 1; } +void f() { __builtin_memcpy(f, f, 1); } `````````` </details> https://github.com/llvm/llvm-project/pull/174184 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
