================
@@ -6343,11 +6343,17 @@ namespace {
   };
 } // end anonymous namespace
 
-static void
-fillDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc DASTL,
-                                 const ParsedAttributesView &Attrs) {
-  for (const ParsedAttr &AL : Attrs) {
-    if (AL.getKind() == ParsedAttr::AT_AddressSpace) {
+static void fillDependentAddressSpaceTypeLoc(
+    DependentAddressSpaceTypeLoc DASTL,
+    ArrayRef<const ParsedAttributesView *> AttrLists) {
+  for (const ParsedAttributesView *Attrs : AttrLists) {
+    for (const ParsedAttr &AL : *Attrs) {
+      if (AL.getKind() != ParsedAttr::AT_AddressSpace)
+        continue;
+      // Skip an attribute that did not produce a type: one diagnosed as
+      // invalid, or one whose argument is missing or is not an expression.
+      if (AL.isInvalid() || AL.getNumArgs() != 1 || !AL.isArgExpr(0))
+        continue;
----------------
akash-manna-sky wrote:

No — the first AT_AddressSpace found isn't always the one that produced the 
type:
`void *v __attribute__((address_space)) __attribute__((address_space(AS)));`
The first attribute is diagnosed (wrong arity) and produces no type, but comes 
first in the list. Without these checks we'd match it and read getArgAsExpr(0) 
out of bounds. Added this case to the tests.

https://github.com/llvm/llvm-project/pull/216348
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to