[cfe-commits] [PATCH] Fix crash-on-invalid when passing 128-bit integers to attributes that expect ICEs
Douglas Gregor
dgregor at apple.com
Fri Jun 29 14:50:30 PDT 2012
On Jun 15, 2012, at 10:58 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> Now with a patch. Excuse me for the noise.
>
> On Fri, Jun 15, 2012 at 10:55 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>> Hello,
>>
>> The attached patch fixes crash-on-invalid when passing 128-bit
>> integers to attributes that expect ICEs, for example:
>>
>> void attr6(void *ptr) __attribute__((nonnull(0x10000000000000001i128)));
>>
>> The root cause of the problem is using getZExtValue() on 128-bit integers.
>>
>> Please review.
>>
>> Dmitri
+/// \brief Check if E is a valid integer constant expression. May output an
+/// error.
///
+/// \param AttrArgNum argument number used in diagnostics.
+///
+/// \param E expression to check.
+///
+/// \param [out] Val ICE value.
+static bool checkICEWithOverflow(Sema &S,
+ StringRef AttrName, SourceLocation AttrLoc,
+ unsigned AttrArgNum, const Expr *E,
+ uint64_t &Val) {
+ // The argument must be an integer constant expression.
+ llvm::APSInt Int;
+ if (E->isTypeDependent() || E->isValueDependent() ||
+ !E->isIntegerConstantExpr(Int, S.Context)) {
+ S.Diag(AttrLoc, diag::err_attribute_argument_n_not_int)
+ << AttrName << AttrArgNum << E->getSourceRange();
+ return false;
+ }
Could we get a specialized diagnostic for the case where E is type- or value-dependent? At least users will know that, in those cases, we can't support arguments that depend on a template parameter.
Otherwise, looks good!
- Doug
More information about the cfe-commits
mailing list