This revision was automatically updated to reflect the committed changes.
Closed by commit rG6081ccf4a3b6: Apply function attributes through array
declarators (authored by chill).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75109/new/
https://reviews.llvm.org/D75109
Files:
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/attr-noreturn.c
clang/test/Sema/attr-noreturn.c
Index: clang/test/Sema/attr-noreturn.c
===================================================================
--- clang/test/Sema/attr-noreturn.c
+++ clang/test/Sema/attr-noreturn.c
@@ -42,3 +42,34 @@
}
typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{'noreturn' attribute takes no arguments}}
+
+
+typedef void fn_t(void);
+
+fn_t *fp __attribute__((noreturn));
+void __attribute__((noreturn)) f6(int i) {
+ fp();
+}
+
+fn_t *fps[4] __attribute__((noreturn));
+void __attribute__((noreturn)) f7(int i) {
+ fps[i]();
+}
+
+extern fn_t *ifps[] __attribute__((noreturn));
+void __attribute__((noreturn)) f8(int i) {
+ ifps[i]();
+}
+
+void __attribute__((noreturn)) f9(int n) {
+ extern int g9(int, fn_t **);
+ fn_t *fp[n] __attribute__((noreturn));
+ int i = g9(n, fp);
+ fp[i]();
+}
+
+typedef fn_t *fptrs_t[4];
+fptrs_t ps __attribute__((noreturn));
+void __attribute__((noreturn)) f10(int i) {
+ ps[i]();
+}
Index: clang/test/CodeGen/attr-noreturn.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/attr-noreturn.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -S -emit-llvm %s -o - | FileCheck %s
+
+typedef void (*fptrs_t[4])(void);
+fptrs_t p __attribute__((noreturn));
+
+void __attribute__((noreturn)) f() {
+ p[0]();
+}
+// CHECK: call
+// CHECK-NEXT: unreachable
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -6502,6 +6502,7 @@
Desugar,
Attributed,
Parens,
+ Array,
Pointer,
BlockPointer,
Reference,
@@ -6522,6 +6523,10 @@
} else if (isa<ParenType>(Ty)) {
T = cast<ParenType>(Ty)->getInnerType();
Stack.push_back(Parens);
+ } else if (isa<ConstantArrayType>(Ty) || isa<VariableArrayType>(Ty) ||
+ isa<IncompleteArrayType>(Ty)) {
+ T = cast<ArrayType>(Ty)->getElementType();
+ Stack.push_back(Array);
} else if (isa<PointerType>(Ty)) {
T = cast<PointerType>(Ty)->getPointeeType();
Stack.push_back(Pointer);
@@ -6599,6 +6604,27 @@
case MacroQualified:
return wrap(C, cast<MacroQualifiedType>(Old)->getUnderlyingType(), I);
+ case Array: {
+ if (const auto *CAT = dyn_cast<ConstantArrayType>(Old)) {
+ QualType New = wrap(C, CAT->getElementType(), I);
+ return C.getConstantArrayType(New, CAT->getSize(), CAT->getSizeExpr(),
+ CAT->getSizeModifier(),
+ CAT->getIndexTypeCVRQualifiers());
+ }
+
+ if (const auto *VAT = dyn_cast<VariableArrayType>(Old)) {
+ QualType New = wrap(C, VAT->getElementType(), I);
+ return C.getVariableArrayType(
+ New, VAT->getSizeExpr(), VAT->getSizeModifier(),
+ VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange());
+ }
+
+ const auto *IAT = cast<IncompleteArrayType>(Old);
+ QualType New = wrap(C, IAT->getElementType(), I);
+ return C.getIncompleteArrayType(New, IAT->getSizeModifier(),
+ IAT->getIndexTypeCVRQualifiers());
+ }
+
case Pointer: {
QualType New = wrap(C, cast<PointerType>(Old)->getPointeeType(), I);
return C.getPointerType(New);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits