[llvm-dev] Problem with intrinsic::trap insertion instead of null pointer dereference

HEITZMANN Frédéric 218168 via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 21 05:49:37 PDT 2015


Sorry for meaningless attachments of drafts, Outlook strikes back.

--
fred

De : llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] De la part de HEITZMANN Frédéric 218168 via llvm-dev
Envoyé : mercredi 21 octobre 2015 14:46
À : llvm-dev at lists.llvm.org
Cc : LLOPARD Ivan 222352 <Ivan.LLOPARD at cea.fr>
Objet : [llvm-dev] Problem with intrinsic::trap insertion instead of null pointer dereference

Hi everyone,

Llvm detects zero pointer dereference in CFG simplify and insert intrinsic::trap (at least with -O1 or -O2).
Problem 1 : I find it unfortunate not to be able to disable it, and allow a specific target to handle it its own way (with MMU fault or dedicated HW stuff).
>> Is there a trick to avoid this ?

Problem 2 : Unless special care is taken in LLVM backend, DAG select will fail on trap, without a clear indication of the guilty C fragment
>> Should the frontend emit at least a warning ?

Thanks for your help.

--
Fred

Example :
C code (many lines remove for the sake of clarity) :



struct s;

struct s{

                struct s *next;

};



struct s* foo (struct s *a){

                struct s *b = 0;

                b->next = a;

                return b;

}

LLVM (clang -O2 -emit-llvm) :



%struct.s = type { %struct.s* }



; Function Attrs: noreturn nounwind

define noalias %struct.s* @foo(%struct.s* nocapture readnone %a) #0 {

entry:

  tail call void @llvm.trap()

  unreachable

}



; Function Attrs: noreturn nounwind

declare void @llvm.trap() #1



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151021/6cdd2880/attachment.html>


More information about the llvm-dev mailing list