llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

__builtin_object_size

Open llvmbot opened this issue 17 years ago • 10 comments

Bugzilla Link 4380
Resolution FIXED
Resolved on Mar 01, 2010 21:36
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @echristo

Extended Description

In this example, builtin_object_size is not lowered by llvm-gcc.

typedef struct _MyFoo { int x, y; } MyFoo; void foobar() { int y; #pragma omp parallel for schedule(dynamic,4) for (y=0; y < 64; y++) { MyFoo *p, *q; __builtin___memcpy_chk (q, p, sizeof(p), __builtin_object_size (q, 0)); } }

llvmbot avatar Jun 12 '09 23:06 llvmbot

Fixed now.

echristo avatar Mar 02 '10 05:03 echristo

Crap. Forgot the openmp. Not fixed.

echristo avatar Dec 22 '09 23:12 echristo

I fixed this a while back.

echristo avatar Dec 22 '09 23:12 echristo

The difference is caused by this change in pop_gimplify_context:

#ifndef ENABLE_LLVM /* LLVM wants to know about gimple formal temps. */ for (t = c->temps; t ; t = TREE_CHAIN (t)) DECL_GIMPLE_FORMAL_TEMP_P (t) = 0; #else t = 0; #endif

In this case, failing to clear DECL_GIMPLE_FORMAL_TEMP_P for the symbol to which the result of the builtin_object_size call is assigned, results in the "val_only" bit being clear during the tree walk of the call, hence the gimplifier thinks it needs to put the builtin_object_size function symbol into a temp as well. Logically it seems the val_only bit should be set by the tree walker when stepping into the callee node of the call, but I'm sure that would have wide ranging effects....

llvmbot avatar Jun 25 '09 03:06 llvmbot

It is the omp lowering pass; it does not do this in gcc-4.2, and the file omp-low.c, which contains that pass, is identical. I guess the thing to do is step through them in parallel. (The magic flag is spelled -fopenmp, btw, if you're still reading you probably knew that).

llvmbot avatar Jun 24 '09 02:06 llvmbot

Hm, the gcc earlier phases have broken down the call into

t = &builtin_object_size; call t(...)

That's vicious. Probably the right idea is to find what's doing that and stop it.

llvmbot avatar Jun 24 '09 00:06 llvmbot

Ah, additional data. You're right, it's not.

llvmbot avatar Jun 24 '09 00:06 llvmbot

Are you sure it is lowered when -fopnemp is used ?

llvmbot avatar Jun 24 '09 00:06 llvmbot

Actually, it is lowered to -1, and then the memcpy_chk expansion decides it is OK to lower that to a plain memcpy since nothing about the object size is known, like this: call void @​llvm.memcpy.i32(i8* %2, i8* %3, i32 4, i32 1) The final 1 is alignment, not anything to do with object-size. I think this is OK.

llvmbot avatar Jun 23 '09 23:06 llvmbot

This is easy to fix. It should be lowered to -1 / 0 when the size is unknown.

llvmbot avatar Jun 13 '09 23:06 llvmbot