Re: [PATCH] D16112: PR26111: segmentation fault with __attribute__((mode(QI))) on function declaration

2016-01-14 Thread Denis Zobnin via cfe-commits
d.zobnin.bugzilla updated this revision to Diff 44859.
d.zobnin.bugzilla added a comment.

Thanks for the review! Updated the patch: added Subjects line for the attribute 
and removed the "err_attr_wrong_decl" diagnostics.


http://reviews.llvm.org/D16112

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-mode.c

Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3391,13 +3391,8 @@
   QualType OldTy;
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
-  else if (ValueDecl *VD = dyn_cast(D))
-OldTy = VD->getType();
-  else {
-S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
-  << Attr.getName() << Attr.getRange();
-return;
-  }
+  else
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3470,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -1954,6 +1954,7 @@
   unsigned getMinRequiredArguments() const;
 
   QualType getReturnType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return getType()->getAs()->getReturnType();
   }
 
@@ -1964,6 +1965,7 @@
 
   /// \brief Determine the type of an expression that calls this function.
   QualType getCallResultType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return 
getType()->getAs()->getCallResultType(getASTContext());
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2844,8 +2844,6 @@
   InGroup;
 def err_complex_mode_vector_type : Error<
   "type of machine mode does not support base vector types">;
-def err_attr_wrong_decl : Error<
-  "%0 attribute invalid on this declaration, requires typedef or value">;
 def warn_attribute_nonnull_no_pointers : Warning<
   "'nonnull' attribute applied to function with no pointer arguments">,
   InGroup;
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -878,6 +878,8 @@
 
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
+  let Subjects = SubjectList<[Var, TypedefName], ErrorDiag,
+ "ExpectedVariableOrTypedef">;
   let Args = [IdentifierArgument<"Mode">];
   let Documentation = [Undocumented];
 }
Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -24,6 +24,9 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
+__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{'mode' attribute only applies to variables and typedefs}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' 
attribute only applies to variables and typedefs}}
+
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
 typedef _Complex float c64 __attribute((mode(DC)));


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3391,13 +3391,8 @@
   QualType OldTy;
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
-  else if (ValueDecl *VD = dyn_cast(D))
-OldTy = VD->getType();
-  else {
-S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
-  << Attr.getName() << Attr.getRange();
-return;
-  }
+  else
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3470,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -1954,6 +1954,7 @@
   unsigned getMinRequiredArguments() const;
 
   QualType getReturnType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return 

Re: [PATCH] D16112: PR26111: segmentation fault with __attribute__((mode(QI))) on function declaration

2016-01-14 Thread Alexey Bataev via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL257868: PR26111: segmentation fault with 
__attribute__((mode(QI))) on function… (authored by ABataev).

Changed prior to commit:
  http://reviews.llvm.org/D16112?vs=44859=44963#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16112

Files:
  cfe/trunk/include/clang/AST/Decl.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/Sema/attr-mode.c

Index: cfe/trunk/include/clang/AST/Decl.h
===
--- cfe/trunk/include/clang/AST/Decl.h
+++ cfe/trunk/include/clang/AST/Decl.h
@@ -1954,6 +1954,7 @@
   unsigned getMinRequiredArguments() const;
 
   QualType getReturnType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return getType()->getAs()->getReturnType();
   }
 
@@ -1964,6 +1965,7 @@
 
   /// \brief Determine the type of an expression that calls this function.
   QualType getCallResultType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return 
getType()->getAs()->getCallResultType(getASTContext());
   }
 
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2851,8 +2851,6 @@
   InGroup;
 def err_complex_mode_vector_type : Error<
   "type of machine mode does not support base vector types">;
-def err_attr_wrong_decl : Error<
-  "%0 attribute invalid on this declaration, requires typedef or value">;
 def warn_attribute_nonnull_no_pointers : Warning<
   "'nonnull' attribute applied to function with no pointer arguments">,
   InGroup;
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -879,6 +879,8 @@
 
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
+  let Subjects = SubjectList<[Var, TypedefName], ErrorDiag,
+ "ExpectedVariableOrTypedef">;
   let Args = [IdentifierArgument<"Mode">];
   let Documentation = [Undocumented];
 }
Index: cfe/trunk/test/Sema/attr-mode.c
===
--- cfe/trunk/test/Sema/attr-mode.c
+++ cfe/trunk/test/Sema/attr-mode.c
@@ -24,6 +24,9 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
+__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{'mode' attribute only applies to variables and typedefs}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' 
attribute only applies to variables and typedefs}}
+
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
 typedef _Complex float c64 __attribute((mode(DC)));
Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -3391,13 +3391,8 @@
   QualType OldTy;
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
-  else if (ValueDecl *VD = dyn_cast(D))
-OldTy = VD->getType();
-  else {
-S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
-  << Attr.getName() << Attr.getRange();
-return;
-  }
+  else
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3470,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,


Index: cfe/trunk/include/clang/AST/Decl.h
===
--- cfe/trunk/include/clang/AST/Decl.h
+++ cfe/trunk/include/clang/AST/Decl.h
@@ -1954,6 +1954,7 @@
   unsigned getMinRequiredArguments() const;
 
   QualType getReturnType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return getType()->getAs()->getReturnType();
   }
 
@@ -1964,6 +1965,7 @@
 
   /// \brief Determine the type of an expression that calls this function.
   QualType getCallResultType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return getType()->getAs()->getCallResultType(getASTContext());
   }
 
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2851,8 +2851,6 @@
   InGroup;
 def err_complex_mode_vector_type : 

Re: [PATCH] D16112: PR26111: segmentation fault with __attribute__((mode(QI))) on function declaration

2016-01-14 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


http://reviews.llvm.org/D16112



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16112: PR26111: segmentation fault with __attribute__((mode(QI))) on function declaration

2016-01-12 Thread Denis Zobnin via cfe-commits
d.zobnin.bugzilla created this revision.
d.zobnin.bugzilla added a reviewer: aaron.ballman.
d.zobnin.bugzilla added a subscriber: cfe-commits.

Allow "mode" attribute to be applied to VarDecl, not ValueDecl (which includes 
FunctionDecl and EnumConstantDecl), emit an error if this attribute is used 
with function declarations and enum constants.

http://reviews.llvm.org/D16112

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-mode.c

Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3372,11 +3372,11 @@
   QualType OldTy;
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
-  else if (ValueDecl *VD = dyn_cast(D))
+  else if (VarDecl *VD = dyn_cast(D))
 OldTy = VD->getType();
   else {
-S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
-  << Attr.getName() << Attr.getRange();
+S.Diag(D->getLocation(), diag::err_mode_requires_typedef_or_variable)
+<< Attr.getRange();
 return;
   }
 
@@ -3451,7 +3451,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -1954,6 +1954,7 @@
   unsigned getMinRequiredArguments() const;
 
   QualType getReturnType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return getType()->getAs()->getReturnType();
   }
 
@@ -1964,6 +1965,7 @@
 
   /// \brief Determine the type of an expression that calls this function.
   QualType getCallResultType() const {
+assert(getType()->getAs() && "Expected a FunctionType!");
 return 
getType()->getAs()->getCallResultType(getASTContext());
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2838,14 +2838,14 @@
   "mode attribute only supported for integer and floating-point types">;
 def err_mode_wrong_type : Error<
   "type of machine mode does not match type of base type">;
+def err_mode_requires_typedef_or_variable : Error<
+  "mode attribute invalid on this declaration, requires typedef or variable">;
 def warn_vector_mode_deprecated : Warning<
   "specifying vector types with the 'mode' attribute is deprecated; "
   "use the 'vector_size' attribute instead">,
   InGroup;
 def err_complex_mode_vector_type : Error<
   "type of machine mode does not support base vector types">;
-def err_attr_wrong_decl : Error<
-  "%0 attribute invalid on this declaration, requires typedef or value">;
 def warn_attribute_nonnull_no_pointers : Warning<
   "'nonnull' attribute applied to function with no pointer arguments">,
   InGroup;
Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -24,6 +24,9 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
+__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{mode attribute invalid on this declaration}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{mode 
attribute invalid on this declaration}}
+
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
 typedef _Complex float c64 __attribute((mode(DC)));


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3372,11 +3372,11 @@
   QualType OldTy;
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
-  else if (ValueDecl *VD = dyn_cast(D))
+  else if (VarDecl *VD = dyn_cast(D))
 OldTy = VD->getType();
   else {
-S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
-  << Attr.getName() << Attr.getRange();
+S.Diag(D->getLocation(), diag::err_mode_requires_typedef_or_variable)
+<< Attr.getRange();
 return;
   }
 
@@ -3451,7 +3451,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -1954,6 +1954,7 @@
   unsigned getMinRequiredArguments() const;
 
   QualType getReturnType() const {
+

Re: [PATCH] D16112: PR26111: segmentation fault with __attribute__((mode(QI))) on function declaration

2016-01-12 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

I think the better way to fix this is to add a Subjects line in Attr.td that 
limits the mode attribute to just TypedefNameDecl and VarDecl, then remove 
err_attr_wrong_decl entirely.


http://reviews.llvm.org/D16112



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits