[cfe-commits] [PATCH] Invariants (and Assume Aligned) - Clang
Dmitri Gribenko
gribozavr at gmail.com
Wed Dec 5 13:28:11 PST 2012
Please update docs/LanguageExtensions.html with descriptions of these two new builtins.
================
Comment at: lib/Sema/SemaChecking.cpp:1605
@@ +1604,3 @@
+ // We can't check the value of a dependent argument.
+ if (!Arg->isTypeDependent() && !Arg->isValueDependent()) {
+ llvm::APSInt Result;
----------------
Should we just reject these cases? Seems like we would silently accept it without checking.
Or would it get checked during template instantiation?
================
Comment at: test/Sema/builtin-assume-aligned.c:37
@@ +36,2 @@
+}
+
----------------
Still not enough :)
Please add:
__builtin_assume_aligned(a, 1ULL << 63);
int test9(int *a, int z) {
a = __builtin_assume_aligned(a, z + 1); // not a constant expression
return a[0];
}
template<int z>
int test10(int *a) {
a = __builtin_assume_aligned(a, z + 1); // value-dependent
return a[0];
}
void test10_inst(int *a) {
test10<32>(a); // power of 2
test10<42>(a); // not a power of 2
}
template<typename T>
int test11(int *a, T z) {
a = __builtin_assume_aligned(a, z + 1); // value-dependent
return a[0];
}
void test11_inst(int *a) {
test11(a, 42);
}
int test12(int *a) {
a = __builtin_assume_aligned(a, 32, "abc"); // wrong type
return a[0];
}
int test13(int *a, int z) {
a = __builtin_assume_aligned(a, z); // not a constant
return a[0];
}
================
Comment at: lib/Sema/SemaChecking.cpp:1610-1613
@@ +1609,6 @@
+
+ if (Result.getLimitedValue() > +llvm::Value::MaximumAlignment ||
+ !Result.isUnsigned())
+ return Diag(TheCall->getLocStart(), diag::err_argument_invalid_range)
+ << "0" << +llvm::Value::MaximumAlignment << Arg->getSourceRange();
+ if (!Result.isPowerOf2())
----------------
What is the purpose of the '+' in '+llvm::Value::MaximumAlignment'?
http://llvm-reviews.chandlerc.com/D149
More information about the cfe-commits
mailing list