1 |
On 09/05/18 23:50, Ian Zimmerman wrote: |
2 |
> Code may be "security-sensitive" but buggy. Is the compiler writer |
3 |
> really responsible for guessing what the programmer meant to accomplish |
4 |
> with buggy code? |
5 |
|
6 |
What do you mean by "buggy"? |
7 |
|
8 |
> It would of course be preferable if the compiler could |
9 |
> just abort with an error when it detects UB, but that turns out to be |
10 |
> very hard to impossible in the case of C. That's just a built in |
11 |
> problem with the language. |
12 |
|
13 |
So if the compiler can't detect undefined behaviour, how the hell do you |
14 |
expect the programmer to? |
15 |
|
16 |
Oh - and please explain - what is buggy about wanting the following |
17 |
program to compile and actually *do* what the code is asking, rather |
18 |
than compiling to a no-op ... |
19 |
|
20 |
int main () { |
21 |
int a, b, c; |
22 |
a = 2; |
23 |
b = 4; |
24 |
c = 6; |
25 |
} |
26 |
|
27 |
Note I did say the problem is almost invariably when hardware gets |
28 |
involved - what happens if it's |
29 |
|
30 |
int main () { |
31 |
void *a; |
32 |
a = 0x00ff; |
33 |
*a = 6; |
34 |
} |
35 |
|
36 |
and 0x00ff is the address of your network adaptor? Do you want THAT to |
37 |
be optimised away "because it doesn't do anything"? |
38 |
|
39 |
That's why I expect LVM/Clang is much better - because I believe Intel |
40 |
is heavily involved they provide guarantees about how the compiler will |
41 |
interact with hardware, when the C standard explicitly avoids specifying |
42 |
it (imho, the standard should require a compiler to document how it |
43 |
handles things like that ...). (Yes I believe there is some compiler |
44 |
option to make that work, but I'm pretty certain that either is or was |
45 |
undefined behaviour to start with? And if it is now standard, it's |
46 |
probably because some clever idiot optimised the "code which doesn't do |
47 |
anything" away and they had to define a way of stopping it?) |
48 |
|
49 |
Cheers, |
50 |
Wol |