r218258 - Fix evatuated value of __builtin_object_size according to its
Hans Wennborg
hans at chromium.org
Mon Sep 22 17:12:52 PDT 2014
r218288 should hopefully fix it.
On Mon, Sep 22, 2014 at 2:43 PM, Yaron Keren <yaron.keren at gmail.com> wrote:
> Hi,
>
> This fails on Visual C++ 2013 update 3, 32 bit:
>
> -- Testing: 1 tests, 1 threads --
> FAIL: Clang :: Sema/builtin-object-size.c (1 of 1)
> ******************** TEST 'Clang :: Sema/builtin-object-size.c' FAILED
> ********************
> Script:
> --
> C:/llvm-clean/msvc/RelWithDebInfo/bin/clang.EXE -cc1 -internal-isystem
> C:\llvm-clean\msvc\RelWithDebInfo\bin\..\lib\clang\3.6.0\include
> -fsyntax-only -verify
> C:\llvm-clean\tools\clang\test\Sema\builtin-object-size.c
> C:/llvm-clean/msvc/RelWithDebInfo/bin/clang.EXE -cc1 -internal-isystem
> C:\llvm-clean\msvc\RelWithDebInfo\bin\..\lib\clang\3.6.0\include
> -fsyntax-only -triple x86_64-apple-darwin9 -verify
> C:\llvm-clean\tools\clang\test\Sema\builtin-object-size.c
> --
> Exit Code: 1
>
> Command Output (stdout):
> --
> Command 0: "C:/llvm-clean/msvc/RelWithDebInfo/bin/clang.EXE" "-cc1"
> "-internal-isystem"
> "C:\llvm-clean\msvc\RelWithDebInfo\bin\..\lib\clang\3.6.0\include"
> "-fsyntax-only" "-verify"
> "C:\llvm-clean\tools\clang\test\Sema\builtin-object-size.c"
> Command 0 Result: 1
> Command 0 Output:
>
>
> Command 0 Stderr:
> error: 'warning' diagnostics seen but not expected:
> File C:\llvm-clean\tools\clang\test\Sema\builtin-object-size.c Line 32:
> incompatible redeclaration of library function 'memcpy'
> error: 'note' diagnostics seen but not expected:
> File C:\llvm-clean\tools\clang\test\Sema\builtin-object-size.c Line 32:
> 'memcpy' is a builtin with type 'void *(void *, const void *, unsigned int)'
> 2 errors generated.
>
> Yaron
>
>
> 2014-09-22 20:12 GMT+03:00 Fariborz Jahanian <fjahanian at apple.com>:
>>
>> Author: fjahanian
>> Date: Mon Sep 22 12:11:59 2014
>> New Revision: 218258
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=218258&view=rev
>> Log:
>> Fix evatuated value of __builtin_object_size according to its
>> 'type' argument when it cannot be determined which objects ptr
>> points to at compile time. rdar://18334276
>>
>> Modified:
>> cfe/trunk/lib/AST/ExprConstant.cpp
>> cfe/trunk/test/Sema/builtin-object-size.c
>>
>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=218258&r1=218257&r2=218258&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Sep 22 12:11:59 2014
>> @@ -6052,8 +6052,20 @@ bool IntExprEvaluator::TryEvaluateBuilti
>> return false;
>> }
>>
>> - // If we can prove the base is null, lower to zero now.
>> - if (!Base.getLValueBase()) return Success(0, E);
>> + if (!Base.getLValueBase()) {
>> + // It is not possible to determine which objects ptr points to at
>> compile time,
>> + // __builtin_object_size should return (size_t) -1 for type 0 or 1
>> + // and (size_t) 0 for type 2 or 3.
>> + llvm::APSInt TypeIntVaue;
>> + const Expr *ExprType = E->getArg(1);
>> + if (!ExprType->EvaluateAsInt(TypeIntVaue, Info.Ctx))
>> + return false;
>> + if (TypeIntVaue == 0 || TypeIntVaue == 1)
>> + return Success(-1, E);
>> + if (TypeIntVaue == 2 || TypeIntVaue == 3)
>> + return Success(0, E);
>> + return Error(E);
>> + }
>>
>> QualType T = GetObjectType(Base.getLValueBase());
>> if (T.isNull() ||
>>
>> Modified: cfe/trunk/test/Sema/builtin-object-size.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtin-object-size.c?rev=218258&r1=218257&r2=218258&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/Sema/builtin-object-size.c (original)
>> +++ cfe/trunk/test/Sema/builtin-object-size.c Mon Sep 22 12:11:59 2014
>> @@ -26,3 +26,20 @@ void f4(const char *fmt, ...) {
>> __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning
>> {{'__builtin___vsnprintf_chk' will always overflow destination buffer}}
>> }
>>
>> +// rdar://18334276
>> +typedef unsigned long size_t;
>> +void * memcset(void *restrict dst, int src, size_t n);
>> +void * memcpy(void *restrict dst, const void *restrict src, size_t n);
>> +
>> +#define memset(dest, src, len) __builtin___memset_chk(dest, src, len,
>> __builtin_object_size(dest, 0))
>> +#define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len,
>> __builtin_object_size(dest, 0))
>> +#define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len,
>> __builtin_object_size(dest, 4))
>> +#define NULL ((void *)0)
>> +
>> +void f5(void)
>> +{
>> + char buf[10];
>> + memset((void *)0x100000000ULL, 0, 0x1000);
>> + memcpy((char *)NULL + 0x10000, buf, 0x10);
>> + memcpy1((char *)NULL + 0x10000, buf, 0x10); // expected-error
>> {{argument should be a value from 0 to 3}}
>> +}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list