Issues with target regions in executable and library

Hi all,

one of my colleagues reported an issue, when having target regions in the executable and a library.
The problem is that during the execution for both target regions the same code (coming from the library) is executed. Is this a bug, known bug, or does this not work by design?

I run below experiment with a quite recent trunk version of LLVM and the output is:

Hello from foo. 0

Which also suggests that the code was actually offloaded to the device.
Also specifying device(0) and device(1) doesn't help to see the right result.

Only adding if(0) or executing the code on a machine with no device provides the expected result:

Hello from main. 1
Hello from foo. 1

We appreciate any hints how this could be fixed.

Best
Joachim

----- main.c -----

#include <stdio.h>
#include <omp.h>

void foo(){
   #pragma omp target
   {
     printf("Hello from foo. %i\n",omp_is_initial_device());
   }
}

----- lib.c -----

#include <stdio.h>
#include <omp.h>

void foo();

int main(){
   #pragma omp target
   {
     printf("Hello from main. %i\n",omp_is_initial_device());
   }
   foo();

   return 0;
}

----- compile & run -----

clang -shared -fPIC -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -g lib.c -o libmylib.so

clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda main.c -L. -lmylib -Wl,--rpath,.

./a.out