[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

Kees Cook via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 10 13:38:24 PST 2024


kees wrote:

Thanks! It's fixed for me now. I continue to be highly unlucky, though, and keep finding weird stuff. It seems to segfault just parsing libc headers under `-D_FORTIFY_SOURCE=3` (but not `=2` or lower):

```
0.      Program arguments: /srv/built-compilers/llvm/counted_by/install/bin/clang -Wall -O2 -fstrict-flex-arrays=3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fsanitize=bounds -fsanitize=object-size -fsanitize-undefined-trap-on-error -c -o array-bounds.o array-bounds.c                                                                                                                        
1.      <eof> parser at end of file                                                                                             
2.      Per-file LLVM IR generation                                                                                             
3.      /usr/include/x86_64-linux-gnu/bits/string_fortified.h:57:1 <Spelling=/usr/include/x86_64-linux-gnu/bits/string_fortified.h:57:8>: Generating code for declaration 'memset'                                                                              
... 
 #4 0x000055ef8b3ac144 clang::DeclContext::decls_begin() const                                                             
 #5 0x000055ef892afcad CountCountedByAttrs(clang::RecordDecl const*) CGBuiltin.cpp:0:0                                          
```

In my header at line 57, I see:

```
__fortify_function void *
__NTH (memset (void *__dest, int __ch, size_t __len))
{
  return __builtin___memset_chk (__dest, __ch, __len,
                                 __glibc_objsize0 (__dest));
}
```

where `__glibc_objsize0` is:

```
sys/cdefs.h:# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
```

I assume something weird is happening with `bdos` here.

https://github.com/llvm/llvm-project/pull/76348


More information about the cfe-commits mailing list