[LLVMdev] [RFC] New function attributes for errno-setting functions

Krzysztof Parzyszek kparzysz at codeaurora.org
Fri Sep 13 13:30:53 PDT 2013


On 9/13/2013 2:23 PM, Hal Finkel wrote:
>
> Maybe the easiest way would be to insert an intrinsic @llvm.errno.read() whenever errno (as a source token) appears in the source as an rvalue (and do some similar thing when it appears as a lvalue). Thoughts?

I think the major problem is still with "errno" defined as a 
preprocessor macro, as it may not look like errno by the time the 
front-end sees it.  Perhaps some configuration test could preprocess 
something like "var = errno;" and check what's really getting stored in 
"var", but it may be unreliable (i.e. not detect all cases).

I thought a bit more about it and I think we will need to have this 
information to prevent similar problems as the one you mentioned in the 
first post.  For example:

   int fd = open(...);
   int saved_errno = errno;
   double s = sqrt(var);
   if (fd == -1)
     fprintf(stderr, "error: %d\n", saved_errno);


With only the information about modifying errno, this code could be 
transformed to

   int fd = open(...);
   double s = sqrt(var);
   int saved_errno = errno;
   if (fd == -1)
     fprintf(stderr, "error: %d\n", saved_errno);

again producing the same situation.


-K


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation



More information about the llvm-dev mailing list