[clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 1 12:45:21 PST 2023


bwendling wrote:

This is a PITA. There are two situations:

1. The expression was processed before getting to the `EmitBoundsCheck` call, and is thus recorded in the `LocalDeclMap` for easy access. Grand!
2. Using a FAM in a `__builtin_dynamic_object_size` cannot have side effects. Also, it may not have been processed before getting to the "emit object size" method, meaning it won't be place in a map.

The first situation isn't too bad. The majority of the time, we can gather the necessary information from `LocalDeclMap` and proceed from there. The `__bdos` situation is far trickier. Let's say you have something horrid like Eli's example:

```
int foo(struct s *p, int index) {
  return __builtin_dynamic_object_size((++p)->array[index], 1);
}
```

This *shouldn't* increment `p`, but we need to get the array size of the element *after* `p`. I suspect that this is probably a horrible security violation in the making, but we at least need to handle such an eventuality gracefully. For a first pass, I think returning `-1` or `0` (depending on the default return value) for *any* pointer arithmetic is probably okay...maybe even the best option?

@kees Thoughts?

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


More information about the cfe-commits mailing list