[llvm-dev] GEP with a null pointer base

Robinson, Paul via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 2 06:29:07 PDT 2017


> Saying “The C++ language lets me assume that that won’t happen, &
> optimize on that basis” is an assumption that that’s what the user
> wants, but you haven’t asked you’ve just assumed, and AFAICT it is an
> incorrect assumption.

Well, by using C++, the programmer agrees that the rules of the language
apply to their program, and the rules of the language say that the
compiler can do whatever it likes.  So whether the user wants it or not,
that's what they have effectively agreed to.

  undefined behavior
  behavior for which this International Standard imposes no requirements
  [ Note: Undefined behavior may be expected when this International
  Standard omits any explicit definition of behavior or when a program
  uses an erroneous construct or erroneous data. Permissible undefined
  behavior ranges from ignoring the situation completely with
  unpredictable results, to behaving during translation or program
  execution in a documented manner characteristic of the environment
  (with or without the issuance of a diagnostic message), to terminating
  a translation or execution (with the issuance of a diagnostic message).
  Many erroneous program constructs do not engender undefined behavior;
  they are required to be diagnosed.
  —end note ]

If you want to argue that it is *more useful* to the programmer to have
diagnostics for undefined behavior as represented in their source code,
I expect you would get essentially universal agreement.  But what I am 
understanding from this thread is an argument that it's a *requirement* 
to diagnose UB, and that is just not what the language requires, and 
consequently not what the user is entitled to.

If I'm misunderstanding, I'd love to be corrected.
Thanks,
--paulr


More information about the llvm-dev mailing list